Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/darccio/errors
https://github.com/darccio/errors
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/darccio/errors
- Owner: darccio
- License: bsd-3-clause
- Created: 2024-07-14T19:27:42.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-07-14T19:35:31.000Z (6 months ago)
- Last Synced: 2024-11-27T04:54:58.720Z (about 1 month ago)
- Language: Go
- Homepage: https://dario.cat/errors
- Size: 1.95 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# errors
`errors` package is a wrapper around Go's `errors` package. It provides a way to wrap errors with additional context about where the error occurred.
It's a simple package to avoid the need to write the following boilerplate to make errors easier to track.
```go
if _, err := os.Open("non-existent-file"); err != nil {
return fmt.Errorf("os.Remove: %w", err)
}
```Instead, you can write:
```go
if _, err := os.Open("non-existent-file"); err != nil {
return errors.Wrap(err)
}
```The error will be wrapped with the file and line number where the error occurred. `Error` will return a string like:
```
example.go:17: file does not exist
```