errors

package module
v0.0.0-...-46b2d18 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: BSD-3-Clause Imports: 7 Imported by: 2

README

Wraps error with function informations where it occured or propagated. Please refer to GoDoc.

License

Please see the LICENSE file for details.

Documentation

Index

Constants

View Source
const ErrUnknown = -1

ErrUnknown defines an unknown error

Variables

This section is empty.

Functions

func Is

func Is(wrapped, orig error) bool

Is wraps errors.Is

func Origin

func Origin(err error) error

Origin returns original error, if wrapped. Otherwise just return err itself.

Types

type Error

type Error interface {
	error
	json.Marshaler
	json.Unmarshaler

	// Returns location of the error
	Scene() ErrorScene

	// Returns code of the error
	Code() int

	// Sets error code
	WithCode(int) Error

	// Returns message of the error
	Message() string

	// Returns functions that propagate the error
	Wrappers() []ErrorScene

	// Origin returns original error
	Origin() error

	// Returns true if the error wrapped
	HasWrappers() bool

	// Equal checks if given error equal original error
	Equal(error) bool

	// Is implements errors.Is
	Is(err error) bool
	// contains filtered or unexported methods
}

Error is a trouble :p. It keeps callers, if asked via Wrap().

func Empty

func Empty() Error

Empty creates error with empty message

func New

func New(message string) Error

New creates new error with given message

func Newf

func Newf(format string, v ...interface{}) Error

Newf creates new error with given formatted message

func Wrap

func Wrap(err error) Error

Wrap wraps given error

func WrapString

func WrapString(msg string) Error

WrapString wraps given error message

func WrapStringf

func WrapStringf(msg string, args ...interface{}) Error

WrapStringf wraps given formatted error message

type ErrorScene

type ErrorScene interface {
	// Returns full path to the file where error occured
	FileName() string

	// Returns line number inside the error file
	LineNumber() int

	// Returns function name that cause the error
	FuncName() string
}

ErrorScene is where an error occured

Jump to

Keyboard shortcuts

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