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

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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)
}