Top 2.1% dependent repos on proxy.golang.org
proxy.golang.org : github.com/brad-jones/goerr/v2
Package goerr adds additional error handling capabilities to go. The problem with standard go errors is that often an error will bubble all the way to the root of a program and then finally be output as a few lines of text without any context to help diagnose the problem. The classic case: You see that single line in a log file or your terminal window and unless have an innate understanding of your program it's difficult to determin exactly where the error was encountered. This package borrows (literally in some cases) from other similar packages: https://github.com/palantir/stacktrace https://github.com/go-errors/errors https://github.com/pkg/errors Dave Cheney has a lot to say on the matter: https://dave.cheney.net/2016/04/27/dont-just-check-errors-handle-them-gracefully The difference is that this package has been built on top of the now standard error wrapping support that was introduced in Go v1.13. We can use Wrap like this: And see output similar to: To borrow from "palantir/stacktrace" the intent is not that we capture the exact state of the stack when an error happens, including every function call. For a library that does that, see github.com/go-errors/errors. The intent here is to attach relevant contextual information (messages, variables) at strategic places along the call stack, keeping stack traces compact and maximally useful. This is totally an experiment, YMMV :) see: https://go.googlesource.com/proposal/+/master/design/go2draft-error-handling-overview.md#draft-design We can emulate the proposed `check` and `handle` using `panic, defer & recover`. Take the same example from the proposal that has been refactored to use goerr. So `Check()` replaces the repetitive `if err != nil { ... }` phrase and `Handle` takes care of the `recover()` logic for you. `Check()` automatically calls `Trace()` on your error. Yeah I get it this looks like exceptions and if you choose to use it like that then thats your prerogative, I'm not going to stop you... but you probably shouldn't! Panicing doesn't work across goroutines for a start and this https://go101.org/article/panic-and-recover-more.html Although there is https://github.com/brad-jones/goasync which makes use of this package to handle errors across goroutines (including panics), reasonable well. I think where this can be really useful is when you say have a function like this:
Registry
-
Source
- Documentation
- JSON
- codemeta.json
purl: pkg:golang/github.com/brad-jones/goerr/v2
License: MIT
Latest release: over 4 years ago
First release: about 5 years ago
Namespace: github.com/brad-jones/goerr
Dependent packages: 7
Dependent repositories: 6
Stars: 0 on GitHub
Forks: 0 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: 2 days ago