tlog.app/go/errors@v0.9.0/README.md (about) 1 [![Documentation](https://pkg.go.dev/badge/tlog.app/go/errors)](https://pkg.go.dev/tlog.app/go/errors?tab=doc) 2 [![Go workflow](https://github.com/tlog-dev/errors/actions/workflows/go.yml/badge.svg)](https://github.com/tlog-dev/errors/actions/workflows/go.yml) 3 [![CircleCI](https://circleci.com/gh/tlog-dev/errors.svg?style=svg)](https://circleci.com/gh/tlog-dev/errors) 4 [![codecov](https://codecov.io/gh/tlog-dev/errors/branch/master/graph/badge.svg)](https://codecov.io/gh/tlog-dev/errors) 5 [![Go Report Card](https://goreportcard.com/badge/tlog.app/go/errors)](https://goreportcard.com/report/tlog.app/go/errors) 6 ![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/tlog-dev/errors?sort=semver) 7 8 # errors 9 10 Stdlib `errors` package extension. `go1.13` `errors.Is` and `errors.As` are the same functions as in stdlib (not even copies). 11 12 ```go 13 // as usual 14 err = errors.New("msg") 15 16 // do not capture caller info 17 err = errors.NewNoLoc("msg") 18 19 // fmt.Sprintf like 20 err = errors.New("message %v", "args") 21 22 // one Frame higher 23 err = errors.NewDepth(1, "msg") 24 25 // the same result as previous 26 pc := loc.Caller(1) 27 err = errors.NewLoc(pc, "msg") 28 29 // Wrap error 30 err = errors.Wrap(err, "msg %v", "args") 31 32 // all the same function types are available 33 err = errors.WrapNoLoc(err, "msg") 34 35 err = errors.WrapDepth(err, 1, "msg %v", "args") 36 37 err = errors.WrapLoc(err, pc, "msg %v", "args") 38 ``` 39 40 ## Caller 41 42 Caller frame can be added to error so later you can get to know where error was generated. It's added by default and captures instruction calling `errors.(Wrap|New)*`. 43 44 Caller is moved to a separate module [github.com/nikandfor/loc](https://github.com/nikandfor/loc). 45 46 ```go 47 pc := loc.Caller(1) 48 49 pc = loc.FuncEntry(1) 50 ```