Documentation
¶
Index ¶
- func Annotate(annotation string, err error) error
- func AnnotateAll(annotation string, errs ...error) []error
- func As(err error, target interface{}) bool
- func Caller(err error) error
- func FileLocation(depth, nameLen int) string
- func Is(err, target error) bool
- func New(m string) error
- func Unwrap(err error) error
- type M
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Annotate ¶ added in v0.0.3
Annotate returns an error representing the original error and the supplied annotation.
func AnnotateAll ¶ added in v0.0.3
AnnotateAll returns a slice of errors representing the original errors and the supplied annotation.
func Caller ¶ added in v0.0.3
Caller returns an error annotated with the location of its immediate caller.
Example ¶
package main
import (
"fmt"
"os"
"cloudeng.io/errors"
)
func main() {
err := errors.Caller(os.ErrNotExist)
fmt.Printf("%v\n", err)
fmt.Printf("%v\n", errors.Unwrap(err))
}
Output: errors/caller_test.go:17: file does not exist file does not exist
func FileLocation ¶ added in v0.0.3
FileLocation returns the callers location as a filepath and line number. Depth follows the convention for runtime.Caller. The filepath is the trailing nameLen components of the filename returned by runtime.Caller. A nameLen of 2 is generally the best compromise between brevity and precision since it includes the enclosing directory component as well as the filename.
Example ¶
package main
import (
"fmt"
"cloudeng.io/errors"
)
func main() {
fmt.Println(errors.FileLocation(1, 1))
fmt.Println(errors.FileLocation(1, 2))
}
Output: caller_test.go:75 errors/caller_test.go:76
Types ¶
type M ¶
type M struct {
// contains filtered or unexported fields
}
M represents multiple errors. It is thread safe. Typical usage is:
errs := errors.M{} ... errs.Append(err) ... return errs.Err()