Skip to content

Commit

Permalink
fix oops errors fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mscno committed Aug 28, 2024
1 parent 9557abb commit b6008f1
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 40 deletions.
6 changes: 3 additions & 3 deletions already_exists.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions deadline_exceeded.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions failed_precondition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions generate/error.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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

)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
6 changes: 3 additions & 3 deletions internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions invalid_argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions not_found.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions permission_denied.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions resource_exhausted.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions unauthenticated.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions unavailable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions unimplemented.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions unknown.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b6008f1

Please sign in to comment.