Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jbowes/cling
Clear and obvious wrapping for Go error values
https://github.com/jbowes/cling
error-handling errors go go2 golang
Last synced: 2 months ago
JSON representation
Clear and obvious wrapping for Go error values
- Host: GitHub
- URL: https://github.com/jbowes/cling
- Owner: jbowes
- License: bsd-2-clause
- Created: 2019-05-06T12:01:53.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-10-03T12:43:27.000Z (about 5 years ago)
- Last Synced: 2024-06-21T04:48:02.701Z (6 months ago)
- Topics: error-handling, errors, go, go2, golang
- Language: Go
- Homepage:
- Size: 20.5 KB
- Stars: 5
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
cling
Clear and obvious wrapping for Go error values
## Introduction
Introduction | [Examples] | [Contributing]🚧 ___Disclaimer___: _`cling` is alpha quality software. The API may change
without warning between revisions._ 🚧`cling` provides a clear and obvious error wrapping API for the new [Go] 2/1.13+
[errors](https://godoc.org/golang.org/x/xerrors) package. If you prefer a
specific function over a [formatting directive](https://godoc.org/golang.org/x/xerrors#Errorf),
and an API that returns a nil error when the error to wrap is nil, then `cling`
is for you.## Examples
[Introduction] | Examples | [Contributing]For complete examples and usage, see the [GoDoc documentation](https://godoc.org/github.com/jbowes/cling).
_Wrapping an error_
```go
err := errors.New("an error")
wrapped := cling.Wrap(err, "wrapped")// Wrapped errors can be programatically inspected
fmt.Print(xerrors.Is(wrapped, err)) // true
```_Sealing an error_
```go
err := errors.New("an error")
sealed := cling.Seal(err, "sealed")// Sealed errors cannot be programatically inspected
fmt.Print(xerrors.Is(sealed, err)) // false
```Both `Wrap` and `Seal` provide format specifier versions(`Wrapf`, `Sealf`),
as well.### Building APIs on `cling`
`cling/skip` implements the `cling` API with an additional `skip` argument,
allowing creation of APIs on top of `cling` that will no report themselves in
error caller frames.## Contributing
[Introduction] | [Examples] | ContributingI would love your help!
`cling` is still a work in progress. You can help by:
- Opening a pull request to resolve an [open issue][issues].
- Adding a feature or enhancement of your own! If it might be big, please
[open an issue][enhancement] first so we can discuss it.
- Improving this `README` or adding other documentation to `cling`.
- Letting [me] know if you're using `cling`.[introduction]: #introduction
[examples]: #examples
[usage]: #usage
[contributing]: #contributing[go]: https://golang.org
[issues]: ./issues
[bug]: ./issues/new?labels=bug
[enhancement]: ./issues/new?labels=enhancement[me]: https://twitter.com/jrbowes