errors

package module
v0.0.0-...-04d5e5d Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2021 License: MIT Imports: 9 Imported by: 0

README

errors

Documentation

Overview

mainly inspired by Ben Johnson, read the following blog for details: https://middlemost.com/failure-is-your-domain/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Combine

func Combine(errs []error) error

Combine combines multiple errors by concatenating the error messages, no logical stack trace will be preserved. Use it when you need to apply a function to an array of data, and want the process to move on even if one of them returns an error.

func E

func E(args ...interface{}) error

E constructs an *Error with variable number of args, which corresponds to the Class, Msg, Op, Code and Cause fields, all args are optional.

func EConflict

func EConflict(args ...interface{}) error

func EInternal

func EInternal(args ...interface{}) error

func EInvalid

func EInvalid(args ...interface{}) error

func ENotFound

func ENotFound(args ...interface{}) error

func EPermDenied

func EPermDenied(args ...interface{}) error

func ErrCode

func ErrCode(err error) int

ErrCode returns the ErrCode of the first error along the chain, otherwise returns -1.

func ErrMsg

func ErrMsg(err error) string

ErrMsg returns the first human-readable message along the chain, otherwise returns a default generic message.

func F

func F(format string, a ...interface{}) error

F formats according to a format specifier and returns the string as a value that satisfies error. Deprecated: Use NewF instead.

func FuncName

func FuncName() string

func FuncNameWithSkip

func FuncNameWithSkip(skip int) string

func Is

func Is(err error, class Class) bool

Is determines whether the given error has the code along the chain, only the first non-empty Class encountered is considered.

func IsContextCanceled

func IsContextCanceled(err error) bool

func New

func New(text string) error

New is equivalent to errors.New in the standard package.

func NewF

func NewF(format string, a ...interface{}) error

NewF is equivalent to fmt.Errorf in the standard package.

func WrapMySQLError

func WrapMySQLError(err error) error

Types

type Class

type Class string
const (
	Conflict   Class = "conflict"          // Action cannot be performed
	Internal   Class = "internal"          // Internal error
	Invalid    Class = "invalid"           // Validation failed
	NotFound   Class = "not_found"         // Entity does not exist
	PermDenied Class = "permission_denied" // Does not have permission
	Other      Class = "other"             // Unclassified error
)

type Error

type Error struct {
	// For application/machine
	Class Class
	// For users & operators, see methods ErrMsg (users) and Error (operators)
	Msg string
	// For operators
	Op    Op    // logical operation
	Code  int   // error code, which identifies an user-defined error
	Cause error // error from lower level
}

Error defines a standard application error.

func (*Error) Error

func (e *Error) Error() string

type Op

type Op string

Jump to

Keyboard shortcuts

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