diff --git a/already_exists.go b/already_exists.go index df7103c..c0d5e73 100644 --- a/already_exists.go +++ b/already_exists.go @@ -10,16 +10,16 @@ const ErrAlreadyExists = "already exists" func ThrowAlreadyExists(action, kind, name string) error { message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind) - return oops.Code(ErrAlreadyExists).Errorf(message) + return oops.Code(ErrAlreadyExists).Wrap(errors.New(message)) } func ThrowAlreadyExistsr(action, kind, name, reason string) error { message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason) - return oops.Code(ErrAlreadyExists).Errorf(message) + return oops.Code(ErrAlreadyExists).Wrap(errors.New(message)) } func AlreadyExists(message string, KVs ...interface{}) error { - return oops.Code(ErrAlreadyExists).With(KVs...).Errorf(message) + return oops.Code(ErrAlreadyExists).With(KVs...).Wrap(errors.New(message)) } func AlreadyExistsf(format string, a ...interface{}) error { diff --git a/deadline_exceeded.go b/deadline_exceeded.go index 17d82bf..13516ef 100644 --- a/deadline_exceeded.go +++ b/deadline_exceeded.go @@ -10,16 +10,16 @@ const ErrDeadlineExceeded = "deadline exceeded" func ThrowDeadlineExceeded(action, kind, name string) error { message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind) - return oops.Code(ErrDeadlineExceeded).Errorf(message) + return oops.Code(ErrDeadlineExceeded).Wrap(errors.New(message)) } func ThrowDeadlineExceededr(action, kind, name, reason string) error { message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason) - return oops.Code(ErrDeadlineExceeded).Errorf(message) + return oops.Code(ErrDeadlineExceeded).Wrap(errors.New(message)) } func DeadlineExceeded(message string, KVs ...interface{}) error { - return oops.Code(ErrDeadlineExceeded).With(KVs...).Errorf(message) + return oops.Code(ErrDeadlineExceeded).With(KVs...).Wrap(errors.New(message)) } func DeadlineExceededf(format string, a ...interface{}) error { diff --git a/failed_precondition.go b/failed_precondition.go index df4c748..dcb2ec2 100644 --- a/failed_precondition.go +++ b/failed_precondition.go @@ -10,16 +10,16 @@ const ErrFailedPrecondition = "failed precondition" func ThrowFailedPrecondition(action, kind, name string) error { message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind) - return oops.Code(ErrFailedPrecondition).Errorf(message) + return oops.Code(ErrFailedPrecondition).Wrap(errors.New(message)) } func ThrowFailedPreconditionr(action, kind, name, reason string) error { message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason) - return oops.Code(ErrFailedPrecondition).Errorf(message) + return oops.Code(ErrFailedPrecondition).Wrap(errors.New(message)) } func FailedPrecondition(message string, KVs ...interface{}) error { - return oops.Code(ErrFailedPrecondition).With(KVs...).Errorf(message) + return oops.Code(ErrFailedPrecondition).With(KVs...).Wrap(errors.New(message)) } func FailedPreconditionf(format string, a ...interface{}) error { diff --git a/generate/error.go.tmpl b/generate/error.go.tmpl index 747f8aa..d2ca4b6 100644 --- a/generate/error.go.tmpl +++ b/generate/error.go.tmpl @@ -10,16 +10,16 @@ const Err{{ .ErrorName }} = "{{ .ErrorNameLowerSpaced }}" func Throw{{ .ErrorName }}(action, kind, name string) error { message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind) - return oops.Code(Err{{ .ErrorName }}).Errorf(message) + return oops.Code(Err{{ .ErrorName }}).Wrap(errors.New(message)) } func Throw{{ .ErrorName }}r(action, kind, name, reason string) error { message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason) - return oops.Code(Err{{ .ErrorName }}).Errorf(message) + return oops.Code(Err{{ .ErrorName }}).Wrap(errors.New(message)) } func {{ .ErrorName }}(message string, KVs ...interface{}) error { - return oops.Code(Err{{ .ErrorName }}).With(KVs...).Errorf(message) + return oops.Code(Err{{ .ErrorName }}).With(KVs...).Wrap(errors.New(message)) } func {{ .ErrorName }}f(format string, a ...interface{}) error { diff --git a/go.mod b/go.mod index e345a3c..3923e84 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/mscno/zerrors go 1.23 require ( - github.com/samber/oops v1.10.1 + github.com/samber/oops v1.13.1 github.com/stretchr/testify v1.9.0 ) diff --git a/go.sum b/go.sum index 1cc4895..c47f9d2 100644 --- a/go.sum +++ b/go.sum @@ -9,6 +9,8 @@ github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM= github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA= github.com/samber/oops v1.10.1 h1:qwCE1SUTKDqbShz52r4eykQBvJqjn3mOAjxneWoeNX4= github.com/samber/oops v1.10.1/go.mod h1:xEXk4BLyqajkvCxzpxBnqfzHzRLFk3+g4E+tOJtOPZY= +github.com/samber/oops v1.13.1 h1:ZTKqsTq1F/og29+wS0tb/NJS0RENRyWE3KrIRZLjdY0= +github.com/samber/oops v1.13.1/go.mod h1:xEXk4BLyqajkvCxzpxBnqfzHzRLFk3+g4E+tOJtOPZY= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 h1:3MTrJm4PyNL9NBqvYDSj3DHl46qQakyfqfWo4jgfaEM= diff --git a/internal.go b/internal.go index 5d22ced..a012a8e 100644 --- a/internal.go +++ b/internal.go @@ -10,16 +10,16 @@ const ErrInternal = "internal" func ThrowInternal(action, kind, name string) error { message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind) - return oops.Code(ErrInternal).Errorf(message) + return oops.Code(ErrInternal).Wrap(errors.New(message)) } func ThrowInternalr(action, kind, name, reason string) error { message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason) - return oops.Code(ErrInternal).Errorf(message) + return oops.Code(ErrInternal).Wrap(errors.New(message)) } func Internal(message string, KVs ...interface{}) error { - return oops.Code(ErrInternal).With(KVs...).Errorf(message) + return oops.Code(ErrInternal).With(KVs...).Wrap(errors.New(message)) } func Internalf(format string, a ...interface{}) error { diff --git a/invalid_argument.go b/invalid_argument.go index e0a8cf3..fa9d86e 100644 --- a/invalid_argument.go +++ b/invalid_argument.go @@ -10,16 +10,16 @@ const ErrInvalidArgument = "invalid argument" func ThrowInvalidArgument(action, kind, name string) error { message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind) - return oops.Code(ErrInvalidArgument).Errorf(message) + return oops.Code(ErrInvalidArgument).Wrap(errors.New(message)) } func ThrowInvalidArgumentr(action, kind, name, reason string) error { message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason) - return oops.Code(ErrInvalidArgument).Errorf(message) + return oops.Code(ErrInvalidArgument).Wrap(errors.New(message)) } func InvalidArgument(message string, KVs ...interface{}) error { - return oops.Code(ErrInvalidArgument).With(KVs...).Errorf(message) + return oops.Code(ErrInvalidArgument).With(KVs...).Wrap(errors.New(message)) } func InvalidArgumentf(format string, a ...interface{}) error { diff --git a/not_found.go b/not_found.go index 36c8939..6e61324 100644 --- a/not_found.go +++ b/not_found.go @@ -10,16 +10,16 @@ const ErrNotFound = "not found" func ThrowNotFound(action, kind, name string) error { message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind) - return oops.Code(ErrNotFound).Errorf(message) + return oops.Code(ErrNotFound).Wrap(errors.New(message)) } func ThrowNotFoundr(action, kind, name, reason string) error { message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason) - return oops.Code(ErrNotFound).Errorf(message) + return oops.Code(ErrNotFound).Wrap(errors.New(message)) } func NotFound(message string, KVs ...interface{}) error { - return oops.Code(ErrNotFound).With(KVs...).Errorf(message) + return oops.Code(ErrNotFound).With(KVs...).Wrap(errors.New(message)) } func NotFoundf(format string, a ...interface{}) error { diff --git a/permission_denied.go b/permission_denied.go index 677ab8d..8eccd0e 100644 --- a/permission_denied.go +++ b/permission_denied.go @@ -10,16 +10,16 @@ const ErrPermissionDenied = "permission denied" func ThrowPermissionDenied(action, kind, name string) error { message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind) - return oops.Code(ErrPermissionDenied).Errorf(message) + return oops.Code(ErrPermissionDenied).Wrap(errors.New(message)) } func ThrowPermissionDeniedr(action, kind, name, reason string) error { message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason) - return oops.Code(ErrPermissionDenied).Errorf(message) + return oops.Code(ErrPermissionDenied).Wrap(errors.New(message)) } func PermissionDenied(message string, KVs ...interface{}) error { - return oops.Code(ErrPermissionDenied).With(KVs...).Errorf(message) + return oops.Code(ErrPermissionDenied).With(KVs...).Wrap(errors.New(message)) } func PermissionDeniedf(format string, a ...interface{}) error { diff --git a/resource_exhausted.go b/resource_exhausted.go index b676668..877380f 100644 --- a/resource_exhausted.go +++ b/resource_exhausted.go @@ -10,16 +10,16 @@ const ErrResourceExhausted = "resource exhausted" func ThrowResourceExhausted(action, kind, name string) error { message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind) - return oops.Code(ErrResourceExhausted).Errorf(message) + return oops.Code(ErrResourceExhausted).Wrap(errors.New(message)) } func ThrowResourceExhaustedr(action, kind, name, reason string) error { message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason) - return oops.Code(ErrResourceExhausted).Errorf(message) + return oops.Code(ErrResourceExhausted).Wrap(errors.New(message)) } func ResourceExhausted(message string, KVs ...interface{}) error { - return oops.Code(ErrResourceExhausted).With(KVs...).Errorf(message) + return oops.Code(ErrResourceExhausted).With(KVs...).Wrap(errors.New(message)) } func ResourceExhaustedf(format string, a ...interface{}) error { diff --git a/unauthenticated.go b/unauthenticated.go index 7ccc1f9..aa4d645 100644 --- a/unauthenticated.go +++ b/unauthenticated.go @@ -10,16 +10,16 @@ const ErrUnauthenticated = "unauthenticated" func ThrowUnauthenticated(action, kind, name string) error { message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind) - return oops.Code(ErrUnauthenticated).Errorf(message) + return oops.Code(ErrUnauthenticated).Wrap(errors.New(message)) } func ThrowUnauthenticatedr(action, kind, name, reason string) error { message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason) - return oops.Code(ErrUnauthenticated).Errorf(message) + return oops.Code(ErrUnauthenticated).Wrap(errors.New(message)) } func Unauthenticated(message string, KVs ...interface{}) error { - return oops.Code(ErrUnauthenticated).With(KVs...).Errorf(message) + return oops.Code(ErrUnauthenticated).With(KVs...).Wrap(errors.New(message)) } func Unauthenticatedf(format string, a ...interface{}) error { diff --git a/unavailable.go b/unavailable.go index 2181abd..7ec89e8 100644 --- a/unavailable.go +++ b/unavailable.go @@ -10,16 +10,16 @@ const ErrUnavailable = "unavailable" func ThrowUnavailable(action, kind, name string) error { message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind) - return oops.Code(ErrUnavailable).Errorf(message) + return oops.Code(ErrUnavailable).Wrap(errors.New(message)) } func ThrowUnavailabler(action, kind, name, reason string) error { message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason) - return oops.Code(ErrUnavailable).Errorf(message) + return oops.Code(ErrUnavailable).Wrap(errors.New(message)) } func Unavailable(message string, KVs ...interface{}) error { - return oops.Code(ErrUnavailable).With(KVs...).Errorf(message) + return oops.Code(ErrUnavailable).With(KVs...).Wrap(errors.New(message)) } func Unavailablef(format string, a ...interface{}) error { diff --git a/unimplemented.go b/unimplemented.go index b043480..01fa6bf 100644 --- a/unimplemented.go +++ b/unimplemented.go @@ -10,16 +10,16 @@ const ErrUnimplemented = "unimplemented" func ThrowUnimplemented(action, kind, name string) error { message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind) - return oops.Code(ErrUnimplemented).Errorf(message) + return oops.Code(ErrUnimplemented).Wrap(errors.New(message)) } func ThrowUnimplementedr(action, kind, name, reason string) error { message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason) - return oops.Code(ErrUnimplemented).Errorf(message) + return oops.Code(ErrUnimplemented).Wrap(errors.New(message)) } func Unimplemented(message string, KVs ...interface{}) error { - return oops.Code(ErrUnimplemented).With(KVs...).Errorf(message) + return oops.Code(ErrUnimplemented).With(KVs...).Wrap(errors.New(message)) } func Unimplementedf(format string, a ...interface{}) error { diff --git a/unknown.go b/unknown.go index c003b21..8039feb 100644 --- a/unknown.go +++ b/unknown.go @@ -10,16 +10,16 @@ const ErrUnknown = "unknown" func ThrowUnknown(action, kind, name string) error { message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind) - return oops.Code(ErrUnknown).Errorf(message) + return oops.Code(ErrUnknown).Wrap(errors.New(message)) } func ThrowUnknownr(action, kind, name, reason string) error { message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason) - return oops.Code(ErrUnknown).Errorf(message) + return oops.Code(ErrUnknown).Wrap(errors.New(message)) } func Unknown(message string, KVs ...interface{}) error { - return oops.Code(ErrUnknown).With(KVs...).Errorf(message) + return oops.Code(ErrUnknown).With(KVs...).Wrap(errors.New(message)) } func Unknownf(format string, a ...interface{}) error {