Documentation ¶
Overview ¶
Package errs provides errors for both APIs and CLIs.
This package is primarily meant to provde a transport-agnostic abstraction of errors that can be easily mapped to both Twirp and gRPC.
Errors in this package are not meant to be sent across the wire, so there is no parsing functionality. Rely on the transport-specific mechanism for over-the-wire operations.
Index ¶
- func Append(one error, two error) error
- func IsError(err error) bool
- func NewAborted(message string) error
- func NewAbortedf(format string, args ...interface{}) error
- func NewAlreadyExists(message string) error
- func NewAlreadyExistsf(format string, args ...interface{}) error
- func NewCanceled(message string) error
- func NewCanceledf(format string, args ...interface{}) error
- func NewDataLoss(message string) error
- func NewDataLossf(format string, args ...interface{}) error
- func NewDeadlineExceeded(message string) error
- func NewDeadlineExceededf(format string, args ...interface{}) error
- func NewError(code Code, message string) error
- func NewErrorf(code Code, format string, args ...interface{}) error
- func NewFailedPrecondition(message string) error
- func NewFailedPreconditionf(format string, args ...interface{}) error
- func NewInternal(message string) error
- func NewInternalf(format string, args ...interface{}) error
- func NewInvalidArgument(message string) error
- func NewInvalidArgumentf(format string, args ...interface{}) error
- func NewNotFound(message string) error
- func NewNotFoundf(format string, args ...interface{}) error
- func NewOutOfRange(message string) error
- func NewOutOfRangef(format string, args ...interface{}) error
- func NewPermissionDenied(message string) error
- func NewPermissionDeniedf(format string, args ...interface{}) error
- func NewResourceExhausted(message string) error
- func NewResourceExhaustedf(format string, args ...interface{}) error
- func NewUnauthenticated(message string) error
- func NewUnauthenticatedf(format string, args ...interface{}) error
- func NewUnavailable(message string) error
- func NewUnavailablef(format string, args ...interface{}) error
- func NewUnimplemented(message string) error
- func NewUnimplementedf(format string, args ...interface{}) error
- func NewUnknown(message string) error
- func NewUnknownf(format string, args ...interface{}) error
- type Code
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Append ¶ added in v0.2.0
Append combines the two errors.
If both are nil, this returns nil. If one is nil, this returns two. If two is nil, this returns one.
If both are non-nil this will convert both to errors for this package. The error messages will be concatanated, and the Code will be one of the following:
If both codes are equal, this returns an error with that Code. If the codes are unequal, this returns an error with CodeInternal.
func IsError ¶ added in v0.2.0
IsError returns true if err is an error created by this package.
Returns false if err == nil.nil
func NewAborted ¶ added in v0.2.0
NewAborted is a convenience function for errors with CodeAborted.
func NewAbortedf ¶ added in v0.2.0
NewAbortedf is a convenience function for errors with CodeAborted.
func NewAlreadyExists ¶ added in v0.2.0
NewAlreadyExists is a convenience function for errors with CodeAlreadyExists.
func NewAlreadyExistsf ¶ added in v0.2.0
NewAlreadyExistsf is a convenience function for errors with CodeAlreadyExists.
func NewCanceled ¶ added in v0.2.0
NewCanceled is a convenience function for errors with CodeCanceled.
func NewCanceledf ¶ added in v0.2.0
NewCanceledf is a convenience function for errors with CodeCanceled.
func NewDataLoss ¶ added in v0.2.0
NewDataLoss is a convenience function for errors with CodeDataLoss.
func NewDataLossf ¶ added in v0.2.0
NewDataLossf is a convenience function for errors with CodeDataLoss.
func NewDeadlineExceeded ¶ added in v0.2.0
NewDeadlineExceeded is a convenience function for errors with CodeDeadlineExceeded.
func NewDeadlineExceededf ¶ added in v0.2.0
NewDeadlineExceededf is a convenience function for errors with CodeDeadlineExceeded.
func NewError ¶ added in v0.2.0
NewError returns a new error with a code.
The value of Error() will only contain the message. If you would like to also print the code, you must do this manually.
If the code is invalid, an error with CodeInternal will be returned.
func NewErrorf ¶ added in v0.2.0
NewErrorf returns a new error.
The value of Error() will only contain the message. If you would like to also print the code, you must do this manually.
If the code is invalid, an error with CodeInternal will be returned.
func NewFailedPrecondition ¶ added in v0.2.0
NewFailedPrecondition is a convenience function for errors with CodeFailedPrecondition.
func NewFailedPreconditionf ¶ added in v0.2.0
NewFailedPreconditionf is a convenience function for errors with CodeFailedPrecondition.
func NewInternal ¶ added in v0.2.0
NewInternal is a convenience function for errors with CodeInternal.
func NewInternalf ¶ added in v0.2.0
NewInternalf is a convenience function for errors with CodeInternal.
func NewInvalidArgument ¶ added in v0.2.0
NewInvalidArgument is a convenience function for errors with CodeInvalidArgument.
func NewInvalidArgumentf ¶ added in v0.2.0
NewInvalidArgumentf is a convenience function for errors with CodeInvalidArgument.
func NewNotFound ¶ added in v0.2.0
NewNotFound is a convenience function for errors with CodeNotFound.
func NewNotFoundf ¶ added in v0.2.0
NewNotFoundf is a convenience function for errors with CodeNotFound.
func NewOutOfRange ¶ added in v0.2.0
NewOutOfRange is a convenience function for errors with CodeOutOfRange.
func NewOutOfRangef ¶ added in v0.2.0
NewOutOfRangef is a convenience function for errors with CodeOutOfRange.
func NewPermissionDenied ¶ added in v0.2.0
NewPermissionDenied is a convenience function for errors with CodePermissionDenied.
func NewPermissionDeniedf ¶ added in v0.2.0
NewPermissionDeniedf is a convenience function for errors with CodePermissionDenied.
func NewResourceExhausted ¶ added in v0.2.0
NewResourceExhausted is a convenience function for errors with CodeResourceExhausted.
func NewResourceExhaustedf ¶ added in v0.2.0
NewResourceExhaustedf is a convenience function for errors with CodeResourceExhausted.
func NewUnauthenticated ¶ added in v0.2.0
NewUnauthenticated is a convenience function for errors with CodeUnauthenticated.
func NewUnauthenticatedf ¶ added in v0.2.0
NewUnauthenticatedf is a convenience function for errors with CodeUnauthenticated.
func NewUnavailable ¶ added in v0.2.0
NewUnavailable is a convenience function for errors with CodeUnavailable.
func NewUnavailablef ¶ added in v0.2.0
NewUnavailablef is a convenience function for errors with CodeUnavailable.
func NewUnimplemented ¶ added in v0.2.0
NewUnimplemented is a convenience function for errors with CodeUnimplemented.
func NewUnimplementedf ¶ added in v0.2.0
NewUnimplementedf is a convenience function for errors with CodeUnimplemented.
func NewUnknown ¶ added in v0.2.0
NewUnknown is a convenience function for errors with CodeUnknown.
func NewUnknownf ¶ added in v0.2.0
NewUnknownf is a convenience function for errors with CodeUnknown.
Types ¶
type Code ¶ added in v0.2.0
type Code int
Code is an error code.
Unlike gRPC and Twirp, there is no zero code for success.
All errors must have a valid code. If an error does not have a valid code when performing error operations, a new error with CodeInternal will be returned.
const ( // CodeOK is a sentinel code for no error. // // No error should use this directly. This is returned by GetCode if the error is nil. CodeOK Code = 0 // CodeCanceled indicates the operation was canceled. // // HTTP equivalent: 408 REQUEST TIMEOUT CodeCanceled Code = 1 // CodeUnknown indicates an unknown error. // // This is for errors that do not have specific error information. // // HTTP equivalent: 500 INTERNAL SERVER ERROR CodeUnknown Code = 2 // CodeInvalidArgument indicates that the an invalid argument was specified, for // example missing required arguments and invalid arguments. // // HTTP equivalent: 400 BAD REQUEST CodeInvalidArgument Code = 3 // CodeDeadlineExceeded indicates that a deadline was exceeded, for example a timeout. // // HTTP equivalent: 504 GATEWAY TIMEOUT // Note that Twirp treats this as a 408 REQUEST TIMEOUT, but grpc-gateway treats this // as 504 GATEWAY TIMEOUT. CodeDeadlineExceeded Code = 4 // CodeNotFound indicates that an entity was not found. // // HTTP equivalent: 404 NOT FOUND CodeNotFound Code = 5 // CodeAlreadyExists indicates that entity creation was unsuccesful as the entity // already exists. // // HTTP equivalent: 409 CONFLICT CodeAlreadyExists Code = 6 // CodePermissionDenied indicates the caller does not have permission to perform // the requested operation. // // HTTP equivalent: 403 FORBIDDEN CodePermissionDenied Code = 7 // CodeResourceExhausted indicates some resource has been exhausted, for example // throttling or out-of-space errors. // // HTTP equivalent: 429 TOO MANY REQUESTS // Note that Twirp treats this as 403 FORBIDDEN, but grpc-gateway treats this // as 429 TOO MANY REQUESTS. CodeResourceExhausted Code = 8 // CodeFailedPrecondition indicates operation was rejected because the system is not // in a state required for the operation's execution, for example a non-recursive // non-empty directory deletion. // // HTTP equivalent: 400 BAD REQUEST // Note that Twirp treats this as 412 PRECONDITION FAILED, but grpc-gateway treats this // as 400 BAD REQUEST, and has a note saying this is on purpose (and it makes sense). CodeFailedPrecondition Code = 9 // CodeAborted indicates the operation was aborted, for example when a transaction // is aborted. // // HTTP equivalent: 409 CONFLICT CodeAborted Code = 10 // CodeOutOfRange indicates an operation was attempted past the valid range, for example // seeking or reading past the end of a paginated collection. // // Unlike InvalidArgument, this error indicates a problem that may be fixed if // the system state changes (i.e. adding more items to the collection). // // There is a fair bit of overlap between FailedPrecondition and OutOfRange. // We recommend using OutOfRange (the more specific error) when it applies so // that callers who are iterating through a space can easily look for an // OutOfRange error to detect when they are done. // // HTTP equivant: 400 BAD REQUEST CodeOutOfRange Code = 11 // CodeUnimplemented indicates operation is not implemented or not // supported/enabled in this service. // // HTTP equivalent: 501 NOT IMPLEMENTED CodeUnimplemented Code = 12 // CodeInternal indicates an internal system error. // // HTTP equivalent: 500 INTERNAL SERVER ERROR CodeInternal Code = 13 // This is a most likely a transient condition and may be corrected // by retrying with a backoff. // // HTTP equivalent: 503 SERVICE UNAVAILABLE CodeUnavailable Code = 14 // CodeDataLoss indicates unrecoverable data loss or corruption. // // HTTP equivalent: 500 INTERNAL SERVER ERROR CodeDataLoss Code = 15 // CodeUnauthenticated indicates the request does not have valid // authentication credentials for the operation. This is different than // PermissionDenied, which deals with authorization. // // HTTP equivalent: 401 UNAUTHORIZED CodeUnauthenticated Code = 16 )