gocloud.dev: gocloud.dev/internal/gcerr Index | Files

package gcerr

import "gocloud.dev/internal/gcerr"

Package gcerr provides an error type for Go CDK APIs.

Index

Package Files

errorcode_string.go gcerr.go

func DoNotWrap Uses

func DoNotWrap(err error) bool

DoNotWrap reports whether an error should not be wrapped in the Error type from this package. It returns true if err is a retry error, a context error, io.EOF, or if it wraps one of those.

func ErrorAs Uses

func ErrorAs(err error, target interface{}, errorAs func(error, interface{}) bool) bool

ErrorAs is a helper for the ErrorAs method of an API's portable type. It performs some initial nil checks, and does a single level of unwrapping when err is a *gcerr.Error. Then it calls its errorAs argument, which should be a driver implementation of ErrorAs.

type Error Uses

type Error struct {
    Code ErrorCode
    // contains filtered or unexported fields
}

An Error describes a Go CDK error.

func New Uses

func New(c ErrorCode, err error, callDepth int, msg string) *Error

New returns a new error with the given code, underlying error and message. Pass 1 for the call depth if New is called from the function raising the error; pass 2 if it is called from a helper function that was invoked by the original function; and so on.

func Newf Uses

func Newf(c ErrorCode, err error, format string, args ...interface{}) *Error

Newf uses format and args to format a message, then calls New.

func (*Error) Error Uses

func (e *Error) Error() string

func (*Error) Format Uses

func (e *Error) Format(s fmt.State, c rune)

func (*Error) FormatError Uses

func (e *Error) FormatError(p xerrors.Printer) (next error)

func (*Error) Unwrap Uses

func (e *Error) Unwrap() error

Unwrap returns the error underlying the receiver, which may be nil.

type ErrorCode Uses

type ErrorCode int

An ErrorCode describes the error's category.

const (
    // Returned by the Code function on a nil error. It is not a valid
    // code for an error.
    OK  ErrorCode = 0

    // The error could not be categorized.
    Unknown ErrorCode = 1

    // The resource was not found.
    NotFound ErrorCode = 2

    // The resource exists, but it should not.
    AlreadyExists ErrorCode = 3

    // A value given to a Go CDK API is incorrect.
    InvalidArgument ErrorCode = 4

    // Something unexpected happened. Internal errors always indicate
    // bugs in the Go CDK (or possibly the underlying service).
    Internal ErrorCode = 5

    // The feature is not implemented.
    Unimplemented ErrorCode = 6

    // The system was in the wrong state.
    FailedPrecondition ErrorCode = 7

    // The caller does not have permission to execute the specified operation.
    PermissionDenied ErrorCode = 8

    // Some resource has been exhausted, typically because a service resource limit
    // has been reached.
    ResourceExhausted ErrorCode = 9

    // The operation was canceled.
    Canceled ErrorCode = 10

    // The operation timed out.
    DeadlineExceeded ErrorCode = 11
)

func GRPCCode Uses

func GRPCCode(err error) ErrorCode

GRPCCode extracts the gRPC status code and converts it into an ErrorCode. It returns Unknown if the error isn't from gRPC.

func (ErrorCode) String Uses

func (i ErrorCode) String() string

Package gcerr imports 9 packages (graph) and is imported by 21 packages. Updated 2019-07-22. Refresh now. Tools for package owners.