entc/gen: check for nil error before invoking .As

Signed-off-by: Alex Snast <alexsn@fb.com>
This commit is contained in:
Alex Snast
2020-01-30 13:42:13 +01:00
parent 0428788539
commit 091f9aba12
23 changed files with 266 additions and 2 deletions

File diff suppressed because one or more lines are too long

View File

@@ -71,6 +71,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)
}
@@ -95,6 +98,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)
}
@@ -111,6 +117,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)
}
@@ -135,6 +144,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)
}