errors

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2021 License: MIT Imports: 9 Imported by: 7

Documentation

Index

Constants

View Source
const (
	ExitCodeSuccess int = iota
	ExitCodeError
)

The codes are returned by the application after completion

Variables

This section is empty.

Functions

func CheckErrorAndExit

func CheckErrorAndExit(err error)

CheckErrorAndExit checks if there is an error, display it in the console and exit with a non-zero exit code. Otherwise, exit 0. Note that if the debugMode is true, this will print out the stack trace.

func ErrorStack

func ErrorStack(err error) string

ErrorStack converts the given error to a string, including the stack trace if available

func ExitCode

func ExitCode(err error) int

ExitCode returns the exit code of a command. If the error contains no exit codes, a success code is returned.

func IsContextCanceled

func IsContextCanceled(err error) bool

IsContextCanceled returns `true` if error has occurred by event `context.Canceled` which is not really an error

func Log added in v0.0.4

func Log(err error)

Log logs a statement of the given error. If log.DebugMode is true, the log record contains a stack of errors.

func Recover

func Recover(onPanic func(cause error))

Recover is a method that tries to recover from panics, and if it succeeds, calls the given onPanic function with an error that explains the cause of the panic. This function should only be called from a defer statement.

Types

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error is a custom error

func Errorf

func Errorf(format string, vals ...interface{}) *Error

Errorf creates a new error with the given message. You can use it as a drop-in replacement for fmt.Errorf() to provide descriptive errors in return values.

func New

func New(err interface{}) *Error

New makes an Error from the given value. If that value is already an error then it will be used directly, if not, it will be passed to fmt.Errorf("%v"). The stacktrace will point to the line of code that called New.

func (*Error) Error

func (err *Error) Error() string

Error returns the underlying error's message.

func (*Error) ErrorStack

func (err *Error) ErrorStack() string

ErrorStack returns a string that contains both the error message and the callstack.

func (*Error) Unwrap

func (err *Error) Unwrap() error

Unwrap unpacks wrapped native errors

func (*Error) WithField

func (err *Error) WithField(key string, value interface{}) *Error

WithField adds a new field

type Fields

type Fields map[string]interface{}

Fields contains key/value data

func ExtractFields

func ExtractFields(err error) Fields

ExtractFields extracts fields from err

func (Fields) String

func (fields Fields) String() string

Error returns the underlying error's message.

Jump to

Keyboard shortcuts

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