-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.go
41 lines (40 loc) · 1.22 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2020 cloudeng llc. All rights reserved.
// Use of this source code is governed by the Apache-2.0
// license that can be found in the LICENSE file.
// Package errors provides utility routines for working with errors that
// are compatible with go 1.13+ and for annotating errors. It provides
// errors.M which can be used to collect and work with multiple errors in a
// thread safe manner. It also provides convenience routines for annotating
// existing errors with caller and other information.
//
// errs := errors.M{}
// errs.Append(fn(a))
// errs.Append(fn(b))
// err := errs.Err()
//
// The location of a function's immediate caller (depth of 1) in form of the
// directory/filename:<line> (name len of 2) can be obtained as follows:
//
// errors.Caller(1, 2)
//
// Annotations, can be added as follows:
//
// err := errors.WithCaller(os.ErrNotExist)
//
// Where:
//
// fmt.Printf("%v\n", err)
// fmt.Printf("%v\n", errors.Unwrap(err))
//
// Would produce:
//
// errors/caller_test.go:17: file does not exist
// file does not exist
//
// Annotated errors can be passed to errors.M:
//
// errs := errors.M{}
// errs.Append(errors.WithCaller(fn(a)))
// errs.Append(errors.WithCaller(fn(b)))
// err := errs.Err()
package errors