Errors package for golang
Wrapped on the basis of the "errors" package and added error codes.
Stack printing will be supported in the future.
Features:
- support error codes
- wrapped message
- wrapped error
- compare error
- parse from error
- stack print
go get -u github.com/lockp111/go-errors
// no error code
var err = New("new error")
// with code
var err = New("new error", WithCode(255))
// register error, duplate error code will panic
var (
ErrNotFound = Register(101, "not found")
ErrUnknow = Register(102, "unknow")
)
if err := FindUser(1); err != nil {
return ErrNotFound.WithError(err)
}
err := FindUser(1)
if err == ErrNotFound {
return ErrNotFound.WithMessage("find user")
}