KO
|
EN
gitlite — search
Search
#javascript
#python
#hacktoberfest
#react
#ai
#typescript
#llm
#go
#golang
#android
#machine-learning
#rust
#deep-learning
#linux
errors
★ 65
Open GitHub ↗
clear go error wrapping with caller
Download README (.md)
Explore Similar Repositories
CavemanTcp
:
CavemanTcp is a simple TCP client and server providing callers with easy integration and full control over network reads and writes.
avocado
:
A Variant Caller, Distributed. Apache 2 licensed.
async-done
:
Allows libraries to handle various caller provided asynchronous functions uniformly. Maps promises, observables, child processes and streams, and callbacks to callback style.
BaseCaller
:
Use truecaller token to retrieve data
Spectre
:
Copy number caller for long read data including SNV utilization
// repository documentation
Was this content helpful?
★ 0
(0 ratings)
Select Rating:
★
★
★
★
★
Submit Feedback
Recent Feedback
×
Download README
Do you want to download the
README.md
file for
errors
?
Download (.md)
# errors [](https://pkg.go.dev/github.com/go-faster/errors#section-documentation) [](https://codecov.io/gh/go-faster/errors) Fork of [xerrors](https://pkg.go.dev/golang.org/x/xerrors) with explicit [Wrap](https://pkg.go.dev/github.com/go-faster/errors#Wrap) instead of `%w`. > Clear is better than clever. ``` go get github.com/go-faster/errors ``` ```go errors.Wrap(err, "message") ``` ## Why * Using `Wrap` is the most explicit way to wrap errors * Wrapping with `fmt.Errorf("foo: %w", err)` is implicit, redundant and error-prone * Parsing `"foo: %w"` is implicit, redundant and slow * The [pkg/errors](https://github.com/pkg/errors) and [xerrors](https://pkg.go.dev/golang.org/x/xerrors) are not maintainted * The [cockroachdb/errors](https://github.com/cockroachdb/errors) is too big * The `errors` has no caller stack trace ## Wrap on nil `Wrap(nil, "msg")` returns a **non-nil** error, matching `fmt.Errorf("msg: %w", err)` with a nil `err` (and unlike `pkg/errors`, which returns nil). Wrap only after checking `err != nil`: ```go if err := do(); err != nil { return errors.Wrap(err, "do") } return nil ``` ## Don't need traces? Call `errors.DisableTrace` or use build tag `noerrtrace`. ## Additional features ### Into Generic type assertion for errors. ```go // Into finds the first error in err's chain that matches target type T, and if so, returns it. // // Into is type-safe alternative to As. func Into[T error](err error) (val T, ok bool) ``` ```go if pathError, ok := errors.Into[*os.PathError](err); ok { fmt.Println("Failed at path:", pathError.Path) } ``` ### Must Must is a generic helper, like template.Must, that wraps a call to a function returning (T, error) and panics if the error is non-nil. ```go func Must[T any](val T, err error) T ``` ## License BSD-3-Clause, same as Go sources