xerror

package module
v0.0.0-...-f450027 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: MIT Imports: 3 Imported by: 11

README

xerror

A simple library to allow optional structured contextual data to be included in error messages, including optional stack traces. Because the xerror type implements Error() it can be used synonymously with the native error type and std lib helpers. However, without using any include context features error output is identical to the std lib's.

For Example

err := fmt.Errorf("wrapped err: %w", xerror.Errorf("not enough %d/30 in bucket", 19).AsKind("CUSTOM_ERROR"))
println(err.Error())

will output:

wrapped err: Kind: CUSTOM_ERROR | not enough 19/30 in bucket

Documentation

Index

Constants

View Source
const NA = Kind("N/A")

Variables

This section is empty.

Functions

This section is empty.

Types

type I

type I interface {
	AsKind(Kind) I
	IsKind(Kind) bool
	Pin() XError

	ToError() error
	XError
	Msg(string) I
	WithStackTrace() I
	// WithParam will append the param key/value pair passed in
	// to the internal map.
	WithParam(string, interface{}) I
	// WithParams will set or merge given params map to use
	// as the param values. Passing nil instead of a map will
	// clear the params completely.
	WithParams(map[string]interface{}) I
	// contains filtered or unexported methods
}

func Errorf

func Errorf(format string, values ...any) I

func New

func New(es string) I

func NewWithKind

func NewWithKind(k Kind, es string) I

type Kind

type Kind string

type XError

type XError interface {
	Error() string
	ErrorMsg() string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳