Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

Awesome Lists containing this project

README

        

cling


Clear and obvious wrapping for Go error values


GoDoc
Alpha Quality
Build Status
GitHub tag
BSD license
codecov
Go Report Card


## 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] | Contributing

I 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