errs

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2019 License: Apache-2.0 Imports: 3 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append added in v0.2.0

func Append(one error, two error) error

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

func IsError(err error) bool

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

func NewAborted(message string) error

NewAborted is a convenience function for errors with CodeAborted.

func NewAbortedf added in v0.2.0

func NewAbortedf(format string, args ...interface{}) error

NewAbortedf is a convenience function for errors with CodeAborted.

func NewAlreadyExists added in v0.2.0

func NewAlreadyExists(message string) error

NewAlreadyExists is a convenience function for errors with CodeAlreadyExists.

func NewAlreadyExistsf added in v0.2.0

func NewAlreadyExistsf(format string, args ...interface{}) error

NewAlreadyExistsf is a convenience function for errors with CodeAlreadyExists.

func NewCanceled added in v0.2.0

func NewCanceled(message string) error

NewCanceled is a convenience function for errors with CodeCanceled.

func NewCanceledf added in v0.2.0

func NewCanceledf(format string, args ...interface{}) error

NewCanceledf is a convenience function for errors with CodeCanceled.

func NewDataLoss added in v0.2.0

func NewDataLoss(message string) error

NewDataLoss is a convenience function for errors with CodeDataLoss.

func NewDataLossf added in v0.2.0

func NewDataLossf(format string, args ...interface{}) error

NewDataLossf is a convenience function for errors with CodeDataLoss.

func NewDeadlineExceeded added in v0.2.0

func NewDeadlineExceeded(message string) error

NewDeadlineExceeded is a convenience function for errors with CodeDeadlineExceeded.

func NewDeadlineExceededf added in v0.2.0

func NewDeadlineExceededf(format string, args ...interface{}) error

NewDeadlineExceededf is a convenience function for errors with CodeDeadlineExceeded.

func NewError added in v0.2.0

func NewError(code Code, message string) error

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

func NewErrorf(code Code, format string, args ...interface{}) error

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

func NewFailedPrecondition(message string) error

NewFailedPrecondition is a convenience function for errors with CodeFailedPrecondition.

func NewFailedPreconditionf added in v0.2.0

func NewFailedPreconditionf(format string, args ...interface{}) error

NewFailedPreconditionf is a convenience function for errors with CodeFailedPrecondition.

func NewInternal added in v0.2.0

func NewInternal(message string) error

NewInternal is a convenience function for errors with CodeInternal.

func NewInternalf added in v0.2.0

func NewInternalf(format string, args ...interface{}) error

NewInternalf is a convenience function for errors with CodeInternal.

func NewInvalidArgument added in v0.2.0

func NewInvalidArgument(message string) error

NewInvalidArgument is a convenience function for errors with CodeInvalidArgument.

func NewInvalidArgumentf added in v0.2.0

func NewInvalidArgumentf(format string, args ...interface{}) error

NewInvalidArgumentf is a convenience function for errors with CodeInvalidArgument.

func NewNotFound added in v0.2.0

func NewNotFound(message string) error

NewNotFound is a convenience function for errors with CodeNotFound.

func NewNotFoundf added in v0.2.0

func NewNotFoundf(format string, args ...interface{}) error

NewNotFoundf is a convenience function for errors with CodeNotFound.

func NewOutOfRange added in v0.2.0

func NewOutOfRange(message string) error

NewOutOfRange is a convenience function for errors with CodeOutOfRange.

func NewOutOfRangef added in v0.2.0

func NewOutOfRangef(format string, args ...interface{}) error

NewOutOfRangef is a convenience function for errors with CodeOutOfRange.

func NewPermissionDenied added in v0.2.0

func NewPermissionDenied(message string) error

NewPermissionDenied is a convenience function for errors with CodePermissionDenied.

func NewPermissionDeniedf added in v0.2.0

func NewPermissionDeniedf(format string, args ...interface{}) error

NewPermissionDeniedf is a convenience function for errors with CodePermissionDenied.

func NewResourceExhausted added in v0.2.0

func NewResourceExhausted(message string) error

NewResourceExhausted is a convenience function for errors with CodeResourceExhausted.

func NewResourceExhaustedf added in v0.2.0

func NewResourceExhaustedf(format string, args ...interface{}) error

NewResourceExhaustedf is a convenience function for errors with CodeResourceExhausted.

func NewUnauthenticated added in v0.2.0

func NewUnauthenticated(message string) error

NewUnauthenticated is a convenience function for errors with CodeUnauthenticated.

func NewUnauthenticatedf added in v0.2.0

func NewUnauthenticatedf(format string, args ...interface{}) error

NewUnauthenticatedf is a convenience function for errors with CodeUnauthenticated.

func NewUnavailable added in v0.2.0

func NewUnavailable(message string) error

NewUnavailable is a convenience function for errors with CodeUnavailable.

func NewUnavailablef added in v0.2.0

func NewUnavailablef(format string, args ...interface{}) error

NewUnavailablef is a convenience function for errors with CodeUnavailable.

func NewUnimplemented added in v0.2.0

func NewUnimplemented(message string) error

NewUnimplemented is a convenience function for errors with CodeUnimplemented.

func NewUnimplementedf added in v0.2.0

func NewUnimplementedf(format string, args ...interface{}) error

NewUnimplementedf is a convenience function for errors with CodeUnimplemented.

func NewUnknown added in v0.2.0

func NewUnknown(message string) error

NewUnknown is a convenience function for errors with CodeUnknown.

func NewUnknownf added in v0.2.0

func NewUnknownf(format string, args ...interface{}) error

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

	// CodeUnavailable indicates the service is currently unavailable.
	// 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
)

func GetCode added in v0.2.0

func GetCode(err error) Code

GetCode gets the error code.

If the error is nil, this returns CodeOK. If the error is not created by this package, it will return CodeInternal.

Note that gRPC maps to CodeUnknown in the same scenario.

func (Code) String added in v0.2.0

func (c Code) String() string

String returns the string value of c.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL