https://github.com/nofeaturesonlybugs/errors
golang extended error package.
https://github.com/nofeaturesonlybugs/errors
error-handling error-reporting errors go golang stack stacktrace
Last synced: 9 months ago
JSON representation
golang extended error package.
- Host: GitHub
- URL: https://github.com/nofeaturesonlybugs/errors
- Owner: nofeaturesonlybugs
- License: mit
- Created: 2020-09-02T22:37:38.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-06-12T16:04:21.000Z (almost 4 years ago)
- Last Synced: 2025-01-11T07:49:56.502Z (over 1 year ago)
- Topics: error-handling, error-reporting, errors, go, golang, stack, stacktrace
- Language: Go
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.txt
- License: LICENSE
Awesome Lists containing this project
README
[](https://pkg.go.dev/github.com/nofeaturesonlybugs/errors)
[](https://goreportcard.com/report/github.com/nofeaturesonlybugs/errors)
[](https://app.travis-ci.com/nofeaturesonlybugs/errors)
[](https://codecov.io/gh/nofeaturesonlybugs/errors)
[](https://opensource.org/licenses/MIT)
golang package for enhanced errors that capture file and line number information, the call stack, relevant identifiers, and a handle back to the original error for type switching.
Replacement for fmt.Errorf(...):
```go
err := errors.Errorf("Failed to do something; here's a value %v",len(data))
fmt.Printf("%#v\n",err) // Prints full stack trace.
```
Wrap another function's error:
```go
_, err := net.Dial( "tcp", "localhost:8080" )
if err != nil {
return errors.Go( err )
}
```
Obtain the original error in order to type switch:
```go
func connect() error {
_, err := net.Dial( "tcp", "localhost:0" )
if err != nil {
return errors.Go( err )
}
return nil
}
err := connect()
switch errors.Original( err ).(type) {
case *net.OpError:
// We know the original type!
}
```
See the godoc link for more information.