errors

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: MIT Imports: 2 Imported by: 1

README

mozey/errors

Define custom errors with individual codes and an optional common cause

Usage

See tests for usage

git clone https://github.com/mozey/errors.git
cd errors
go test ./...

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmptyCause = NewCause("")

EmptyCause for matching errors created without a cause

Functions

func Cause

func Cause(err error) error

Cause returns the underlying cause of the error

func Is

func Is(err, target error) bool

Is returns true for custom errors defined with this package, if the format code matches

func New

func New(msg string) error

New creates a new error with msg

func NewCause

func NewCause(msg string) error

func NewWithCause

func NewWithCause(cause error, msg string) error

NewWithCause creates a new error with cause and msg

func NewWithCausef

func NewWithCausef(cause error, format string, a ...any) error

NewType creates a new error with cause and formatted msg

func Newf

func Newf(format string, a ...any) error

New creates a new error with formatted msg

func WithStack

func WithStack(err error)

WithStack may be used to annotate err with a stack trace, at the point where it is called. Don't use this when defining custom errors

Types

type Base

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

Base does not implement causer. It's the base for custom errors defined with this package

func (Base) Error

func (e Base) Error() string

type Custom

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

Custom type for defining errors

func (Custom) Cause

func (e Custom) Cause() error

Cause can be used to determine the cause of errors. Useful for grouping related errors, e.g. custom errors defined in the same package

func (Custom) Code

func (e Custom) Code() string

Code is the format string used to create the message value

func (Custom) Error

func (e Custom) Error() string

func (Custom) Is

func (e Custom) Is(err error) bool

Is return true if, the type of the error is ErrExampleType, and the format matches the string passed into the constructor. Think of the format string as the unique error number of code. Do not call errors.Wrap or WithStack when creating errors below

Jump to

Keyboard shortcuts

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