github.com/nikandfor/errors@v0.8.0/README.md (about)

     1  [![Documentation](https://pkg.go.dev/badge/github.com/nikandfor/errors)](https://pkg.go.dev/github.com/nikandfor/errors?tab=doc)
     2  [![Build Status](https://travis-ci.com/nikandfor/errors.svg?branch=master)](https://travis-ci.com/nikandfor/errors)
     3  [![CircleCI](https://circleci.com/gh/nikandfor/errors.svg?style=svg)](https://circleci.com/gh/nikandfor/errors)
     4  [![codecov](https://codecov.io/gh/nikandfor/errors/branch/master/graph/badge.svg)](https://codecov.io/gh/nikandfor/errors)
     5  [![GolangCI](https://golangci.com/badges/github.com/nikandfor/errors.svg)](https://golangci.com/r/github.com/nikandfor/errors)
     6  [![Go Report Card](https://goreportcard.com/badge/github.com/nikandfor/errors)](https://goreportcard.com/report/github.com/nikandfor/errors)
     7  ![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/nikandfor/errors?sort=semver)
     8  
     9  # errors
    10  
    11  Stdlib `errors` package extension. `go1.13` `errors.Is` and `errors.As` are the same functions as in stdlib (not even copies).
    12  
    13  ```go
    14  // as usual
    15  err = errors.New("msg")
    16  
    17  // do not capture caller info
    18  err = errors.NewNoLoc("msg")
    19  
    20  // fmt.Sprintf like
    21  err = errors.New("message %v", "args")
    22  
    23  // one Frame higher
    24  err = errors.NewDepth(1, "msg")
    25  
    26  // the same result as previous
    27  pc := loc.Caller(1)
    28  err = errors.NewLoc(pc, "msg")
    29  
    30  // Wrap error
    31  err = errors.Wrap(err, "msg %v", "args")
    32  
    33  // all the same function types are available
    34  err = errors.WrapNoLoc(err, "msg")
    35  
    36  err = errors.WrapDepth(err, 1, "msg %v", "args")
    37  
    38  err = errors.WrapLoc(err, pc, "msg %v", "args")
    39  ```
    40  
    41  ## Caller
    42  
    43  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)*`.
    44  
    45  Caller is moved to a separate module [github.com/nikandfor/loc](https://github.com/nikandfor/loc).
    46  
    47  ```go
    48  pc := loc.Caller(1)
    49  
    50  pc = loc.FuncEntry(1)
    51  ```