mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
Merge pull request #324 from facebookincubator/nil_before_as
entc/gen: check for nil error before invoking .As
This commit is contained in:
@@ -100,6 +100,9 @@ func (e *NotFoundError) Error() string {
|
||||
|
||||
// IsNotFound returns a boolean indicating whether the error is a not found error.
|
||||
func IsNotFound(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotFoundError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -124,6 +127,9 @@ func (e *NotSingularError) Error() string {
|
||||
|
||||
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
|
||||
func IsNotSingular(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotSingularError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -140,6 +146,9 @@ func (e *NotLoadedError) Error() string {
|
||||
|
||||
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
|
||||
func IsNotLoaded(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotLoadedError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -164,6 +173,9 @@ func (e *ConstraintError) Unwrap() error {
|
||||
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *ConstraintError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
|
||||
@@ -100,6 +100,9 @@ func (e *NotFoundError) Error() string {
|
||||
|
||||
// IsNotFound returns a boolean indicating whether the error is a not found error.
|
||||
func IsNotFound(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotFoundError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -124,6 +127,9 @@ func (e *NotSingularError) Error() string {
|
||||
|
||||
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
|
||||
func IsNotSingular(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotSingularError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -140,6 +146,9 @@ func (e *NotLoadedError) Error() string {
|
||||
|
||||
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
|
||||
func IsNotLoaded(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotLoadedError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -164,6 +173,9 @@ func (e *ConstraintError) Unwrap() error {
|
||||
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *ConstraintError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
|
||||
@@ -100,6 +100,9 @@ func (e *NotFoundError) Error() string {
|
||||
|
||||
// IsNotFound returns a boolean indicating whether the error is a not found error.
|
||||
func IsNotFound(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotFoundError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -124,6 +127,9 @@ func (e *NotSingularError) Error() string {
|
||||
|
||||
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
|
||||
func IsNotSingular(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotSingularError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -140,6 +146,9 @@ func (e *NotLoadedError) Error() string {
|
||||
|
||||
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
|
||||
func IsNotLoaded(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotLoadedError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -164,6 +173,9 @@ func (e *ConstraintError) Unwrap() error {
|
||||
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *ConstraintError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
|
||||
@@ -100,6 +100,9 @@ func (e *NotFoundError) Error() string {
|
||||
|
||||
// IsNotFound returns a boolean indicating whether the error is a not found error.
|
||||
func IsNotFound(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotFoundError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -124,6 +127,9 @@ func (e *NotSingularError) Error() string {
|
||||
|
||||
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
|
||||
func IsNotSingular(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotSingularError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -140,6 +146,9 @@ func (e *NotLoadedError) Error() string {
|
||||
|
||||
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
|
||||
func IsNotLoaded(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotLoadedError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -164,6 +173,9 @@ func (e *ConstraintError) Unwrap() error {
|
||||
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *ConstraintError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
|
||||
@@ -100,6 +100,9 @@ func (e *NotFoundError) Error() string {
|
||||
|
||||
// IsNotFound returns a boolean indicating whether the error is a not found error.
|
||||
func IsNotFound(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotFoundError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -124,6 +127,9 @@ func (e *NotSingularError) Error() string {
|
||||
|
||||
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
|
||||
func IsNotSingular(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotSingularError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -140,6 +146,9 @@ func (e *NotLoadedError) Error() string {
|
||||
|
||||
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
|
||||
func IsNotLoaded(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotLoadedError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -164,6 +173,9 @@ func (e *ConstraintError) Unwrap() error {
|
||||
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *ConstraintError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
|
||||
@@ -100,6 +100,9 @@ func (e *NotFoundError) Error() string {
|
||||
|
||||
// IsNotFound returns a boolean indicating whether the error is a not found error.
|
||||
func IsNotFound(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotFoundError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -124,6 +127,9 @@ func (e *NotSingularError) Error() string {
|
||||
|
||||
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
|
||||
func IsNotSingular(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotSingularError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -140,6 +146,9 @@ func (e *NotLoadedError) Error() string {
|
||||
|
||||
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
|
||||
func IsNotLoaded(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotLoadedError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -164,6 +173,9 @@ func (e *ConstraintError) Unwrap() error {
|
||||
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *ConstraintError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
|
||||
@@ -100,6 +100,9 @@ func (e *NotFoundError) Error() string {
|
||||
|
||||
// IsNotFound returns a boolean indicating whether the error is a not found error.
|
||||
func IsNotFound(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotFoundError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -124,6 +127,9 @@ func (e *NotSingularError) Error() string {
|
||||
|
||||
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
|
||||
func IsNotSingular(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotSingularError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -140,6 +146,9 @@ func (e *NotLoadedError) Error() string {
|
||||
|
||||
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
|
||||
func IsNotLoaded(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotLoadedError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -164,6 +173,9 @@ func (e *ConstraintError) Unwrap() error {
|
||||
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *ConstraintError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
|
||||
@@ -100,6 +100,9 @@ func (e *NotFoundError) Error() string {
|
||||
|
||||
// IsNotFound returns a boolean indicating whether the error is a not found error.
|
||||
func IsNotFound(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotFoundError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -124,6 +127,9 @@ func (e *NotSingularError) Error() string {
|
||||
|
||||
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
|
||||
func IsNotSingular(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotSingularError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -140,6 +146,9 @@ func (e *NotLoadedError) Error() string {
|
||||
|
||||
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
|
||||
func IsNotLoaded(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotLoadedError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -164,6 +173,9 @@ func (e *ConstraintError) Unwrap() error {
|
||||
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *ConstraintError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
|
||||
@@ -100,6 +100,9 @@ func (e *NotFoundError) Error() string {
|
||||
|
||||
// IsNotFound returns a boolean indicating whether the error is a not found error.
|
||||
func IsNotFound(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotFoundError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -124,6 +127,9 @@ func (e *NotSingularError) Error() string {
|
||||
|
||||
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
|
||||
func IsNotSingular(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotSingularError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -140,6 +146,9 @@ func (e *NotLoadedError) Error() string {
|
||||
|
||||
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
|
||||
func IsNotLoaded(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotLoadedError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -164,6 +173,9 @@ func (e *ConstraintError) Unwrap() error {
|
||||
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *ConstraintError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
|
||||
@@ -100,6 +100,9 @@ func (e *NotFoundError) Error() string {
|
||||
|
||||
// IsNotFound returns a boolean indicating whether the error is a not found error.
|
||||
func IsNotFound(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotFoundError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -124,6 +127,9 @@ func (e *NotSingularError) Error() string {
|
||||
|
||||
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
|
||||
func IsNotSingular(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotSingularError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -140,6 +146,9 @@ func (e *NotLoadedError) Error() string {
|
||||
|
||||
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
|
||||
func IsNotLoaded(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotLoadedError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -164,6 +173,9 @@ func (e *ConstraintError) Unwrap() error {
|
||||
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *ConstraintError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
|
||||
@@ -100,6 +100,9 @@ func (e *NotFoundError) Error() string {
|
||||
|
||||
// IsNotFound returns a boolean indicating whether the error is a not found error.
|
||||
func IsNotFound(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotFoundError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -124,6 +127,9 @@ func (e *NotSingularError) Error() string {
|
||||
|
||||
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
|
||||
func IsNotSingular(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotSingularError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -140,6 +146,9 @@ func (e *NotLoadedError) Error() string {
|
||||
|
||||
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
|
||||
func IsNotLoaded(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotLoadedError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -164,6 +173,9 @@ func (e *ConstraintError) Unwrap() error {
|
||||
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *ConstraintError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
|
||||
@@ -100,6 +100,9 @@ func (e *NotFoundError) Error() string {
|
||||
|
||||
// IsNotFound returns a boolean indicating whether the error is a not found error.
|
||||
func IsNotFound(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotFoundError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -124,6 +127,9 @@ func (e *NotSingularError) Error() string {
|
||||
|
||||
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
|
||||
func IsNotSingular(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotSingularError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -140,6 +146,9 @@ func (e *NotLoadedError) Error() string {
|
||||
|
||||
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
|
||||
func IsNotLoaded(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotLoadedError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
@@ -164,6 +173,9 @@ func (e *ConstraintError) Unwrap() error {
|
||||
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *ConstraintError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user