39 lines
1.3 KiB
Go
39 lines
1.3 KiB
Go
// This package explores some of the most common use cases shared among Go error
|
|
// handling libraries, such as top-level error types, per-error metadata, and
|
|
// error chaining; however, it avoids some of the more complex interfaces
|
|
// related to stack management or peeling back the veneer beneath the Golang
|
|
// runtime. If you need something with greater complexity with a robust
|
|
// featureset that doesn't simply end with error management, this package is not
|
|
// for you. If you want an error management interface that lets you define
|
|
// specific error types, wrap errors from the standard library or the runtime,
|
|
// and inject metadata (key/value- or code-based) without too much additional
|
|
// fuss then this library is for you.
|
|
//
|
|
// Example:
|
|
//
|
|
// var ErrDecoding = errors.NewError("error decoding JSON input")
|
|
// var ErrEncoding = errors.NewError("error encoding JSON input")
|
|
// var ErrReading = errors.NewError("unable to read stream")
|
|
//
|
|
// if err := json.Unmarshal(data, map); err != nil {
|
|
// return ErrDecoding.Do(err)
|
|
// }
|
|
//
|
|
// if b, err := json.Marshal(data); err != nil {
|
|
// return ErrEncoding.Do(err)
|
|
// }
|
|
//
|
|
// func DoSomething(fail bool) error {
|
|
// if fail {
|
|
// return ErrReading
|
|
// }
|
|
// }
|
|
//
|
|
// func DoSomethingElse(fn func() error) error {
|
|
// if err := fn(); err != nil {
|
|
// return ErrDecoding.Do(err)
|
|
// }
|
|
// }
|
|
|
|
package errors
|