errors

package
v1.0.0-gitspaces-beta Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(err error, target any) bool

func Details

func Details(err error) map[string]any

Details unwraps an error and returns its details.

func Is

func Is(err error, target error) bool

func IsAborted

func IsAborted(err error) bool

IsAborted checks if err is aborted error.

func IsConflict

func IsConflict(err error) bool

IsConflict checks if err is conflict error.

func IsInternal

func IsInternal(err error) bool

IsInternal checks if err is internal error.

func IsInvalidArgument

func IsInvalidArgument(err error) bool

IsInvalidArgument checks if err is invalid argument error.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound checks if err is not found error.

func IsPreconditionFailed

func IsPreconditionFailed(err error) bool

IsPreconditionFailed checks if err is precondition failed error.

func Message

func Message(err error) string

Message unwraps an error and returns its message.

func New

func New(text string) error

Types

type Error

type Error struct {
	// Machine-readable status code.
	Status Status

	// Human-readable error message.
	Message string

	// Source error
	Err error

	// Details
	Details map[string]any
}

func Aborted

func Aborted(format string, args ...interface{}) *Error

Aborted is a helper function to return aborted error status.

func AsError

func AsError(err error) (e *Error)

AsError return err as Error.

func Conflict

func Conflict(format string, args ...interface{}) *Error

Conflict is a helper function to return an conflict Error.

func Failed

func Failed(format string, args ...interface{}) *Error

Failed is a helper function to return failed error status.

func Format

func Format(code Status, format string, args ...interface{}) *Error

Format is a helper function to return an Error with a given status and formatted message.

func Internal

func Internal(err error, format string, args ...interface{}) *Error

Internal is a helper function to return an internal Error.

func InvalidArgument

func InvalidArgument(format string, args ...interface{}) *Error

InvalidArgument is a helper function to return an invalid argument Error.

func NotFound

func NotFound(format string, args ...interface{}) *Error

NotFound is a helper function to return an not found Error.

func PreconditionFailed

func PreconditionFailed(format string, args ...interface{}) *Error

PreconditionFailed is a helper function to return an precondition failed error.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface.

func (*Error) SetDetails

func (e *Error) SetDetails(details map[string]any) *Error

func (*Error) SetErr

func (e *Error) SetErr(err error) *Error

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Status

type Status string
const (
	StatusConflict           Status = "conflict"
	StatusInternal           Status = "internal"
	StatusInvalidArgument    Status = "invalid"
	StatusNotFound           Status = "not_found"
	StatusNotImplemented     Status = "not_implemented"
	StatusUnauthorized       Status = "unauthorized"
	StatusFailed             Status = "failed"
	StatusPreconditionFailed Status = "precondition_failed"
	StatusAborted            Status = "aborted"
)

func AsStatus

func AsStatus(err error) Status

AsStatus unwraps an error and returns its code. Non-application errors always return StatusInternal.

Jump to

Keyboard shortcuts

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