Documentation ¶
Overview ¶
Package cgerrors provides a way to return detailed information for an RPC request error. The error is normally JSON encoded.
Index ¶
- Constants
- func Equal(err1 error, err2 error) bool
- func Is(err, target error) bool
- func IsAlreadyExists(err error) bool
- func IsDeadlineExceeded(err error) bool
- func IsInternal(err error) bool
- func IsInvalidArgument(err error) bool
- func IsNotFound(err error) bool
- func IsPermissionDenied(err error) bool
- func IsUnauthenticated(err error) bool
- func IsUnimplemented(err error) bool
- func IsUnknown(err error) bool
- func ToGRPCError(err error) error
- type Error
- func ErrAlreadyExists(a ...interface{}) *Error
- func ErrAlreadyExistsf(format string, a ...interface{}) *Error
- func ErrDeadlineExceeded(a ...interface{}) *Error
- func ErrDeadlineExceededf(format string, a ...interface{}) *Error
- func ErrFailedPrecondition(a ...interface{}) *Error
- func ErrFailedPreconditionf(format string, a ...interface{}) *Error
- func ErrInternal(a ...interface{}) *Error
- func ErrInternalf(format string, a ...interface{}) *Error
- func ErrInvalidArgument(a ...interface{}) *Error
- func ErrInvalidArgumentf(format string, a ...interface{}) *Error
- func ErrNotFound(a ...interface{}) *Error
- func ErrNotFoundf(format string, a ...interface{}) *Error
- func ErrOutOfRange(a ...interface{}) *Error
- func ErrOutOfRangef(format string, a ...interface{}) *Error
- func ErrPermissionDenied(a ...interface{}) *Error
- func ErrPermissionDeniedf(format string, a ...interface{}) *Error
- func ErrUnauthenticated(a ...interface{}) *Error
- func ErrUnauthenticatedf(format string, a ...interface{}) *Error
- func ErrUnavailable(a ...interface{}) *Error
- func ErrUnavailablef(format string, a ...interface{}) *Error
- func ErrUnimplemented(a ...interface{}) *Error
- func ErrUnimplementedf(format string, a ...interface{}) *Error
- func ErrUnknown(a ...interface{}) *Error
- func ErrUnknownf(format string, a ...interface{}) *Error
- func FromError(err error) *Error
- func FromString(err string) (*Error, bool)
- func New(id, detail string, code ErrorCode) *Error
- func Parse(err string) *Error
- func To(err error) *Error
- func Wrap(err error, code ErrorCode, detail string) *Error
- func Wrapf(err error, code ErrorCode, format string, args ...interface{}) *Error
- type ErrorCode
- type ErrorCoder
- type GRPCError
Constants ¶
const ( // CodeOK should be used as the codes.OK. Returned on success. CodeOK = ErrorCode_OK // CodeCanceled indicates the operation was canceled (typically by the caller). CodeCanceled = ErrorCode_Canceled // CodeUnknown error. An example of where this error may be returned is // if an error value received from another address space belongs to // an error-space that is not known in this address space. Also, errors // raised by APIs that do not return enough error information // may be converted to this error. CodeUnknown = ErrorCode_Unknown // CodeInvalidArgument indicates client specified an invalid argument. // Note that this differs from FailedPrecondition. It indicates arguments // that are problematic regardless of the state of the system // (e.g., a malformed file name, or validation errors). CodeInvalidArgument = ErrorCode_InvalidArgument // CodeDeadlineExceeded means operation expired before completion. // For operations that change the state of the system, this error may be // returned even if the operation has completed successfully. For // example, a successful response from a server could have been delayed // long enough for the deadline to expire. CodeDeadlineExceeded = ErrorCode_DeadlineExceeded // CodeNotFound means some requested entity or model (e.g., file or directory) was // not found. CodeNotFound = ErrorCode_NotFound // CodeAlreadyExists means an attempt to create an entity failed because one // already exists. CodeAlreadyExists = ErrorCode_AlreadyExists // CodePermissionDenied indicates the caller does not have permission to // execute the specified operation. It must not be used for rejections // caused by exhausting some resource (use ResourceExhausted // instead for those errors). It must not be // used if the caller cannot be identified (use Unauthenticated // instead for those errors). CodePermissionDenied = ErrorCode_PermissionDenied // CodeResourceExhausted indicates some resource has been exhausted, perhaps // a per-user quota, or perhaps the entire file system is out of space. // // This error code will be generated by the gRPC framework in // out-of-memory and server overload situations, or when a message is // larger than the configured maximum size. CodeResourceExhausted = ErrorCode_ResourceExhausted // CodeFailedPrecondition indicates operation was rejected because the // system is not in a state required for the operation's execution. // For example, directory to be deleted may be non-empty, a rmdir // operation is applied to a non-directory, etc. // // A litmus test that may help a service implementor in deciding // between CodeFailedPrecondition, CodeAborted, and CodeUnavailable: // (a) Use CodeUnavailable if the client can retry just the failing call. // (b) Use CodeAborted if the client should retry at a higher-level // (e.g., restarting a read-modify-write sequence). // (c) Use CodeFailedPrecondition if the client should not retry until // the system state has been explicitly fixed. E.g., if a "rmdir" // fails because the directory is non-empty, FailedPrecondition // should be returned since the client should not retry unless // they have first fixed up the directory by deleting files from it. // (d) Use CodeFailedPrecondition if the client performs conditional // REST Get/Update/Delete on a resource and the resource on the // server does not match the condition. E.g., conflicting // read-modify-write on the same resource. CodeFailedPrecondition = ErrorCode_FailedPrecondition // CodeAborted indicates the operation was aborted, typically due to a // concurrency issue like sequencer check failures, transaction aborts, // etc. // // See litmus test above for deciding between CodeFailedPrecondition, // CodeAborted, and CodeUnavailable. CodeAborted = ErrorCode_Aborted // CodeOutOfRange means operation was attempted past the valid range. // E.g., seeking or reading past end of file. // // Unlike CodeInvalidArgument, this error indicates a problem that may // be fixed if the system state changes. For example, a 32-bit file // system will generate CodeInvalidArgument if asked to read at an // offset that is not in the range [0,2^32-1], but it will generate // CodeOutOfRange if asked to read from an offset past the current // file size. // // There is a fair bit of overlap between CodeFailedPrecondition and // CodeOutOfRange. We recommend using CodeOutOfRange (the more specific // error) when it applies so that callers who are iterating through // a space can easily look for an CodeOutOfRange error to detect when // they are done. CodeOutOfRange = ErrorCode_OutOfRange // CodeUnimplemented indicates operation is not implemented or not // supported/enabled in this service. CodeUnimplemented = ErrorCode_Unimplemented // CodeInternal errors. Means some invariants expected by underlying // system has been broken. If you see one of these errors, // something is very broken. CodeInternal = ErrorCode_Internal // This is a most likely a transient condition and may be corrected // by retrying with a backoff. Note that it is not always safe to retry // non-idempotent operations. // // See litmus test above for deciding between CodeFailedPrecondition, // CodeAborted, and CodeUnavailable. CodeUnavailable = ErrorCode_Unavailable // CodeDataLoss indicates unrecoverable data loss or corruption. CodeDataLoss = ErrorCode_DataLoss // CodeUnauthenticated indicates the request does not have valid // authentication credentials for the operation. CodeUnauthenticated = ErrorCode_Unauthenticated )
ErrorCode new names
const MetaKeyWrapped = "x-err-wrapped"
MetaKeyWrapped adds the error metadata key that keeps the wrapped error value.
Variables ¶
This section is empty.
Functions ¶
func IsAlreadyExists ¶
IsAlreadyExists checks if given error means that given entity already exists.
func IsDeadlineExceeded ¶
IsDeadlineExceeded checks if given error is of type Deadline Exceeded.
func IsInternal ¶
IsInternal checks if the input is an internal error.
func IsInvalidArgument ¶
IsInvalidArgument checks if given error contains a CodeInvalidArgument.
func IsNotFound ¶
IsNotFound checks if given input error is of code NotFound.
func IsPermissionDenied ¶
IsPermissionDenied checks if given error is of type CodePermissionDenied.
func IsUnauthenticated ¶
IsUnauthenticated checks if given error is an unauthenticated error.
func IsUnimplemented ¶ added in v0.0.5
IsUnimplemented checks if given error contains CodeUnimplemented.
func ToGRPCError ¶
ToGRPCError converts an error to GRPC status.Status.
Types ¶
type Error ¶
type Error struct { ID string `json:"id,omitempty"` Code ErrorCode `json:"code,omitempty"` Detail string `json:"detail,omitempty"` Process string `json:"process,omitempty"` Meta map[string]string `json:"meta,omitempty"` // contains filtered or unexported fields }
Error is the error message that has id, it's code and a detail.
func ErrAlreadyExists ¶
func ErrAlreadyExists(a ...interface{}) *Error
ErrAlreadyExists generates a 409 error.
func ErrAlreadyExistsf ¶
ErrAlreadyExistsf generates formatted 409 error.
func ErrDeadlineExceeded ¶
func ErrDeadlineExceeded(a ...interface{}) *Error
ErrDeadlineExceeded generates a 408 error.
func ErrDeadlineExceededf ¶
ErrDeadlineExceededf generates formatted 408 error.
func ErrFailedPrecondition ¶ added in v0.0.21
func ErrFailedPrecondition(a ...interface{}) *Error
ErrFailedPrecondition generates a 400 error.
func ErrFailedPreconditionf ¶ added in v0.0.21
ErrFailedPreconditionf generates a 400 error.
func ErrInternalf ¶
ErrInternalf generates formatted 500 error.
func ErrInvalidArgument ¶
func ErrInvalidArgument(a ...interface{}) *Error
ErrInvalidArgument generates a 400 error.
func ErrInvalidArgumentf ¶
ErrInvalidArgumentf generates formatted 400 error.
func ErrNotFoundf ¶
ErrNotFoundf generates formatted 404 error.
func ErrOutOfRange ¶ added in v0.0.27
func ErrOutOfRange(a ...interface{}) *Error
ErrOutOfRange generates an error with the CodeOutOfRange.
func ErrOutOfRangef ¶ added in v0.0.27
ErrOutOfRangef generates formatted error with the CodeOutOfRange.
func ErrPermissionDenied ¶
func ErrPermissionDenied(a ...interface{}) *Error
ErrPermissionDenied generates a 403 error.
func ErrPermissionDeniedf ¶
ErrPermissionDeniedf generates a 403 error.
func ErrUnauthenticated ¶
func ErrUnauthenticated(a ...interface{}) *Error
ErrUnauthenticated generates a 401 error.
func ErrUnauthenticatedf ¶
ErrUnauthenticatedf generates 401 error with formatted message.
func ErrUnavailable ¶ added in v0.0.25
func ErrUnavailable(a ...interface{}) *Error
ErrUnavailable generates Unavailable error.
func ErrUnavailablef ¶ added in v0.0.25
ErrUnavailablef generates Unavailable error with formatting.
func ErrUnimplemented ¶ added in v0.0.5
func ErrUnimplemented(a ...interface{}) *Error
ErrUnimplemented generates Unimplemented error.
func ErrUnimplementedf ¶ added in v0.0.5
ErrUnimplementedf generates Unimplemented error with formatting.
func ErrUnknown ¶ added in v0.0.23
func ErrUnknown(a ...interface{}) *Error
ErrUnknown generates Unknown error.
func ErrUnknownf ¶ added in v0.0.23
ErrUnknownf generates Unknown error with formatting.
func FromString ¶ added in v0.0.23
FromString parses string error into an Error structure.
func Parse ¶
Parse tries to parse a JSON string into an error. If that fails, it will set the given string as the error detail.
func To ¶
To type check if given error is of *Error type or has encoded ErrorCode in it. Otherwise creates a new error with Unknown code.
func (*Error) GRPCStatus ¶
GRPCStatus implements grpc client interface used to convert statuses.
func (*Error) Is ¶
Is implements errors.Is function interface to check if input error matches this error or the one wrapped.
func (*Error) Unwrap ¶ added in v0.0.25
Unwrap implements errors.Unwrap function internal interface.
func (*Error) WithProcess ¶
WithProcess sets the process for given error.
type ErrorCode ¶
type ErrorCode int32
ErrorCode is a code that defines errors specification.
const ( // Deprecated: use CodeOK instead. ErrorCode_OK ErrorCode = 0 // Deprecated: use CodeCanceled instead. ErrorCode_Canceled ErrorCode = 1 // Deprecated: use CodeUnknown instead. ErrorCode_Unknown ErrorCode = 2 // Deprecated: use CodeInvalidArgument instead. ErrorCode_InvalidArgument ErrorCode = 3 // Deprecated: use CodeDeadlineExceeded instead. ErrorCode_DeadlineExceeded ErrorCode = 4 // Deprecated: use CodeNotFound instead. ErrorCode_NotFound ErrorCode = 5 // Deprecated: use CodeAlreadyExists instead. ErrorCode_AlreadyExists ErrorCode = 6 // Deprecated: use CodePermissionDenied instead. ErrorCode_PermissionDenied ErrorCode = 7 // Deprecated: use CodeResourceExhausted instead. ErrorCode_ResourceExhausted ErrorCode = 8 // Deprecated: use CodeFailedPrecondition instead. ErrorCode_FailedPrecondition ErrorCode = 9 // Deprecated: use CodeAborted instead. ErrorCode_Aborted ErrorCode = 10 // Deprecated: use CodeOutOfRange instead. ErrorCode_OutOfRange ErrorCode = 11 // Deprecated: use CodeUnimplemented instead. ErrorCode_Unimplemented ErrorCode = 12 // Deprecated: use CodeInternal instead. ErrorCode_Internal ErrorCode = 13 ErrorCode_Unavailable ErrorCode = 14 // Deprecated: use CodeDataLoss instead. ErrorCode_DataLoss ErrorCode = 15 // Deprecated: use CodeUnauthenticated instead. ErrorCode_Unauthenticated ErrorCode = 16 )
ErrorCode well known codes. nolint: revive,stylecheck
func (ErrorCode) ToGRPCCode ¶
ToGRPCCode gets the related grpc code.
type ErrorCoder ¶
ErrorCoder is an interface used to obtain an error code from given error within given implementation.