package gcerr
import "gocloud.dev/internal/gcerr"
Package gcerr provides an error type for Go CDK APIs.
Index ¶
- func DoNotWrap(err error) bool
- func ErrorAs(err error, target any, errorAs func(error, any) bool) bool
- type Error
- func New(c ErrorCode, err error, callDepth int, msg string) *Error
- func Newf(c ErrorCode, err error, format string, args ...any) *Error
- func (e *Error) Error() string
- func (e *Error) Format(s fmt.State, c rune)
- func (e *Error) FormatError(p xerrors.Printer) (next error)
- func (e *Error) Unwrap() error
- type ErrorCode
Functions ¶
func DoNotWrap ¶
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 ¶
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.
Types ¶
type Error ¶
type Error struct { // Code is the error code. Code ErrorCode // contains filtered or unexported fields }
An Error describes a Go CDK error.
func New ¶
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 ¶
Newf uses format and args to format a message, then calls New.
func (*Error) Error ¶
Error returns the error as a string.
func (*Error) Format ¶
Format formats the error.
func (*Error) FormatError ¶
FormatError formats the errots.
func (*Error) Unwrap ¶
Unwrap returns the error underlying the receiver, which may be nil.
type ErrorCode ¶
type ErrorCode int
An ErrorCode describes the error's category.
const ( // OK is returned by the Code function on a nil error. It is not a valid // code for an error. OK ErrorCode = 0 // Unknown means that the error could not be categorized. Unknown ErrorCode = 1 // NotFound means that the resource was not found. NotFound ErrorCode = 2 // AlreadyExists means that the resource exists, but it should not. AlreadyExists ErrorCode = 3 // InvalidArguments means that a value given to a Go CDK API is incorrect. InvalidArgument ErrorCode = 4 // Internal means that something unexpected happened. Internal errors always indicate // bugs in the Go CDK (or possibly the underlying service). Internal ErrorCode = 5 // Unimplemented means that the feature is not implemented. Unimplemented ErrorCode = 6 // FailedPrecondition means that the system was in the wrong state. FailedPrecondition ErrorCode = 7 // PermissionDenied means that the caller does not have permission to execute the specified operation. PermissionDenied ErrorCode = 8 // ResourceExhausted means that some resource has been exhausted, typically because a service resource limit // has been reached. ResourceExhausted ErrorCode = 9 // Canceled means that the operation was canceled. Canceled ErrorCode = 10 // DeadlineExceeded means that The operation timed out. DeadlineExceeded ErrorCode = 11 )
func GRPCCode ¶
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 ¶
Source Files ¶
errorcode_string.go gcerr.go
- Version
- v0.41.0 (latest)
- Published
- Mar 30, 2025
- Platform
- windows/amd64
- Imports
- 10 packages
- Last checked
- 4 hours ago –
Tools for package owners.