A wrapper over pkg/errors to enrich and enhance error handling. This package was moved out of vcore/errors for independent use and development.
To use this package, you need to have pkg/errors and this package in your system. For most cases this should mean doing
go get github.com/pkg/errors
go get github.com/skit-ai/errors
Then import this package as import "github.com/skit-ai/errors"
.
The major difference between this major release and the version in vcore/errors is that functions have been demarcated with the functionality they provide and the context they are used in. So to create a basic new error now, all you need to do is call the NewError
function with a message string. For example:
err := NewError("Error happened")
Almost all of the functions support formatted strings so you can also do something like:
num := 5
err := NewError("Errors occured %d times", num)
To chain a new error with an existing one, you need to use functions starting with the name Chain-. For example:
err := NewError("Error happened")
err = ChainError(err, "This happened due to another error")
All functions starting with New- in their name returns a fresh new error and those with Chain- in their name returns an error
chained with the input error
.
Check out the docs to know more.