Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jbowes/vice
Definitions of common bad behaviours for Go error values
https://github.com/jbowes/vice
error-handling errors go go2 golang
Last synced: 2 months ago
JSON representation
Definitions of common bad behaviours for Go error values
- Host: GitHub
- URL: https://github.com/jbowes/vice
- Owner: jbowes
- License: bsd-2-clause
- Created: 2019-05-06T11:59:45.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-03-15T17:14:15.000Z (almost 2 years ago)
- Last Synced: 2024-06-21T03:22:56.055Z (6 months ago)
- Topics: error-handling, errors, go, go2, golang
- Language: Go
- Homepage:
- Size: 46.9 KB
- Stars: 13
- Watchers: 4
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
vice
Standard bad behaviours for Go error values
## Introduction
Introduction | [Examples] | [Usage] | [Contributing]🚧 ___Disclaimer___: _`vice` is alpha quality software. The API may change
without warning between revisions._ 🚧`vice` provides bad behaviours for the new [Go] 2/1.13+ error values.
## Examples
[Introduction] | Examples | [Usage] | [Contributing]*Create an error that implements `NotFound() bool`:*
```go
vice.New(vice.NotFound, "user not found")
```*Wrap an existing error, and add `Timeout() bool`:*
```go
vice.Wrap(err, vice.Timeout, "request timed out")
```For complete examples and usage, see the [GoDoc documentation](https://godoc.org/github.com/jbowes/vice).
## Usage
[Introduction] | [Examples] | Usage | [Contributing]`vice` defines common types of errors, as seen in existing packages, as expressed
through methods on the errors of the form:
```go
BehaviourName() bool // returns true
```Errors of these types can be created and checked by vice. When used with Go 2
error value wrapping, intermediate code layers don't have to know about the
behaviours or types of errors, and may add additional information, without
altering how the error is handled in the topmost layer:```go
// Create an error when your database can't find a user record
err := vice.New(vice.NotFound, "user not found")// many intermediate layers of code, passing the error on, and wrapping it
// ...// In your central request handler middleware
if vice.Is(err, vice.NotFound) {
// respond appropriately to the client
}
```### Building APIs on `vice`
`vice/skip` implements the `vice` API with an additional `skip` argument,
allowing creation of APIs on top of `vice` that will not report themselves in
error caller frames.## Contributing
[Introduction] | [Examples] | [Usage] | ContributingI would love your help!
`vice` 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 `vice`.
- Letting [me] know if you're using `vice`.[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