errcode

package
v0.0.0-...-39628cf Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: AGPL-3.0 Imports: 3 Imported by: 12

Documentation

Index

Constants

View Source
const (
	NotFound     = "not-found"
	InvalidArg   = "invalid-arg"
	Internal     = "internal"
	Unauthorized = "unauthorized"
	TimeOut      = "time-out"
)

Common general error codes

Variables

This section is empty.

Functions

func AltErrorf

func AltErrorf(err error, f string, args ...interface{}) error

AltErrorf replaces the message of err to be the formatted message, but keeps the error code.

func Annotate

func Annotate(err error, msg string) error

Annotate annotates an error but keeps the error code.

func Annotatef

func Annotatef(err error, f string, args ...interface{}) error

Annotatef annotates an error with a formatted message but keeps the error code.

func FromOS

func FromOS(err error) error

FromOS converts os package errors into errcode errors.

func IsInternal

func IsInternal(err error) bool

IsInternal checks if it is an internal error.

func IsInvalidArg

func IsInvalidArg(err error) bool

IsInvalidArg checks if it is an invalid argument error.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound checks if it is a not-found error.

func IsTimeOut

func IsTimeOut(err error) bool

IsTimeOut checks if it is a time-out error.

func IsUnauthorized

func IsUnauthorized(err error) bool

IsUnauthorized checks if it is an unauthorized error.

func Of

func Of(err error) string

Of returns the code of the error. For errors that do not have a code, it returns empty string.

Types

type Error

type Error struct {
	Code    string // code is the type of the error.
	Err     error  // error is the error message, human friendly.
	Message string // alternative message.
}

Error is a generic error with a string error code.

func Add

func Add(code string, err error) *Error

Add creates a new error with code as the error code.

func Errorf

func Errorf(code string, f string, args ...interface{}) *Error

Errorf creates an Error with the given error code.

func Internalf

func Internalf(f string, args ...interface{}) *Error

Internalf creates a new internal error.

func InvalidArgf

func InvalidArgf(f string, args ...interface{}) *Error

InvalidArgf creates a new invalid arugment error.

func NotFoundf

func NotFoundf(f string, args ...interface{}) *Error

NotFoundf creates a new not-found error.

func TimeOutf

func TimeOutf(f string, args ...interface{}) *Error

TimeOutf returns a new time-out error.

func Unauthorizedf

func Unauthorizedf(f string, args ...interface{}) *Error

Unauthorizedf returns an error caused by an unauthrozied request.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the unwrapped error.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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