Categorygithub.com/robert-zaremba/errstack
modulepackage
1.0.2
Repository: https://github.com/robert-zaremba/errstack.git
Documentation: pkg.go.dev

# README

errstack

GoDoc

stacked error wrappers

Package errstack provides a way to augment errors with a functional type and iteratively build new request error.

How to handle errors?

Rule of thumb:

An error should be handled only once. Logging an error is handling an error. So an error should either be logged or propagated.

Motivation

In software we have 3 types of errors:

  • Infrastructure - this errors come from the requests to other services.
  • Domain - this is the type of errors when we detect that our internal application state is wrong.
  • Request - a user request error.

Request errors maps parameters (application inputs) to the cause description (why the value of wrong).

Domain errors usually arise form some model bug or unhandled condition.

Infrastructure errors arise from the system or connection error.

It is very handy to know the place (stack) where the error Infrastructure or Domain error arose - that's why they are threatened especially and are augmented with the stack trace.

Credits

The initial work was done for the AgFlow project.

# Functions

CallAndAssign assigns error returned from the function to the err pointer if needed.
CallAndLog calls function which may return error and logs it.
IsKind reports whether err is an *Error of the given Kind.
IsTimeout checks if given error is a timeout (net/url.Error).
Join creates a new error from list of errors.
Log logs error if it's not nil.
New creates a new error E.
NewBuilder creates new builders with given prefix being appended to each error keys.
NewDomain creates new domain error from string Domain error is classified as an Infrastructure error.
NewDomainF creates new domain error using string formatter.
NewIO creates new infrastructural error from string.
NewIOf creates new infrastructural error using string formatter.
NewReq creates request error from string.
NewReqDetails creates a request error.
NewReqF creates request error from format.
RootErr returns the underlying cause of the error, if possible.
Seq returns a standard error from a string sequence.
UntilFirstDo is utility method for using UntilFirst.
Wrap creates new error using error and string message.
WrapAsDomain creates new domain error using error and string message Domain error is classified as an Infrastructure error.
WrapAsDomainF creates new domain error wrapping given error and using string formatter for description.
WrapAsIO creates new infrastructure error from simple error If input argument is nil, nil is returned.
WrapAsIOf creates new infrastructural error wrapping given error and using string formatter for description.
WrapAsReq creates new request error from simple error If input argument is nil, nil is returned.
WrapAsReqF creates new request error from simple error and creates message from format If input argument is nil, nil is returned.

# Constants

Link target does not exist.
No wrapped key for user with read access.
Internal error causing business domain problem or inconsistency.
Item already exists.
Invalid operation for this type of item.
I/O error such as network failure.
Item is a directory.
Item is not a directory.
Directory not empty.
Item does not exist.
Unclassified error.
Permission denied.
Information withheld.
General request error.
A transient error.

# Structs

ListNode is a representation used by Builder.ToList interface function.
StubPutter ignores all input.
UntilFirst is a struct to easily chain a sequence of operations until a first error arise.

# Interfaces

Builder is a type to incrementally build set of errors under common key structure Builder intentionally doesn't implement standard Error interface.
E is error with more information.
HasStacktrace provides a function to return the the root stacktrace.
HasStatusCode provides a function to return the HTTP status code.
HasUnderlying describes entity (usually an error) which has underlying error.
Logger defines the reporting interface for utils error functions.
Putter is an interface which provides a way to set an error abstracting from it's identifier (key).

# Type aliases

Kind defines the kind of error that must act differently depending on the error.