mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
Merge pull request #323 from facebookincubator/errwrap
entc/gen: add support for wrapped errors
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/facebookincubator/ent/dialect"
|
||||
"github.com/facebookincubator/ent/dialect/sql"
|
||||
"github.com/facebookincubator/ent/dialect/sql/sqlgraph"
|
||||
"golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
// Order applies an ordering on either graph traversal or sql selector.
|
||||
@@ -94,13 +95,13 @@ type NotFoundError struct {
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e *NotFoundError) Error() string {
|
||||
return fmt.Sprintf("ent: %s not found", e.label)
|
||||
return "ent: " + e.label + " not found"
|
||||
}
|
||||
|
||||
// IsNotFound returns a boolean indicating whether the error is a not found error.
|
||||
func IsNotFound(err error) bool {
|
||||
_, ok := err.(*NotFoundError)
|
||||
return ok
|
||||
var e *NotFoundError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
|
||||
// MaskNotFound masks nor found error.
|
||||
@@ -118,13 +119,13 @@ type NotSingularError struct {
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e *NotSingularError) Error() string {
|
||||
return fmt.Sprintf("ent: %s not singular", e.label)
|
||||
return "ent: " + e.label + " not singular"
|
||||
}
|
||||
|
||||
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
|
||||
func IsNotSingular(err error) bool {
|
||||
_, ok := err.(*NotSingularError)
|
||||
return ok
|
||||
var e *NotSingularError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
|
||||
// NotLoadedError returns when trying to get a node that was not loaded by the query.
|
||||
@@ -134,13 +135,13 @@ type NotLoadedError struct {
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e *NotLoadedError) Error() string {
|
||||
return fmt.Sprintf("ent: %s edge was not loaded", e.edge)
|
||||
return "ent: " + e.edge + " edge was not loaded"
|
||||
}
|
||||
|
||||
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
|
||||
func IsNotLoaded(err error) bool {
|
||||
_, ok := err.(*NotLoadedError)
|
||||
return ok
|
||||
var e *NotLoadedError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
|
||||
// ConstraintError returns when trying to create/update one or more entities and
|
||||
@@ -153,7 +154,7 @@ type ConstraintError struct {
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e ConstraintError) Error() string {
|
||||
return fmt.Sprintf("ent: constraint failed: %s", e.msg)
|
||||
return "ent: constraint failed: " + e.msg
|
||||
}
|
||||
|
||||
// Unwrap implements the errors.Wrapper interface.
|
||||
@@ -163,8 +164,8 @@ func (e *ConstraintError) Unwrap() error {
|
||||
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
_, ok := err.(*ConstraintError)
|
||||
return ok
|
||||
var e *ConstraintError
|
||||
return xerrors.As(err, &e)
|
||||
}
|
||||
|
||||
func isSQLConstraintError(err error) (*ConstraintError, bool) {
|
||||
|
||||
Reference in New Issue
Block a user