Documentation ¶
Overview ¶
Package errors provides extra functionalities to that of Go's stdlib errors package.
TODO: fields. e.g., errors.Msg("error message", errors.Str("name", name), errors.Err(err))
or errors.With().Str("name", name).Err(err).Msg("error message") or errors.With().StrErr("name", nameErr).Msg("error message")
(sounds like structured logging? exactly!)
Index ¶
- Variables
- func Arg(argName string, err error, fields ...EntityError) error
- func ArgMsg(argName, errMsg string, fields ...EntityError) error
- func ArgWrap(argName, contextMessage string, err error, fields ...EntityError) error
- func IsCallError(e error) bool
- func Wrap(contextMessage string, causeErr error) error
- type ArgumentError
- type CallError
- type EntityError
- type Unwrappable
Constants ¶
This section is empty.
Variables ¶
var ( As = errors.As Is = errors.Is New = errors.New // Prefer Msg instead of New as it has better semantic Msg = errors.New Unwrap = errors.Unwrap )
Wraps Go's errors
var ErrUnimplemented = Msg("unimplemented")
ErrUnimplemented is used to declare that a functionality, or part of it, has not been implemented. This could be well mapped to some protocols' status code, e.g., HTTP's 501 and gRPC's 12 .
Functions ¶
func ArgMsg ¶
func ArgMsg(argName, errMsg string, fields ...EntityError) error
func IsCallError ¶
Types ¶
type ArgumentError ¶
type ArgumentError interface {
ArgumentName() string
}
type EntityError ¶
func Ent ¶
func Ent(entityIdentifier string, err error) EntityError
Ent creates an instance of error which conforms EntityError. It takes entityIdentifier which could be the name, key or URL of an entity. The entityIdentifier should describe the 'what' while err describes the 'why'.
// Describes that the file ".config.yaml" does not exist. errors.Ent("./config.yaml", os.ErrNotExist) // Describes that the site "https://example.com" is unreachable. errors.Ent("https://example.com/", errors.Msg("unreachable"))
func EntMsg ¶
func EntMsg(entityIdentifier string, errMsg string) EntityError
EntMsg creates an instance of error from an entitity identifier and the error message which describes why the entity is considered error.