-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrapped errors (github.com/pkg/errors) #28
Comments
Alternative idea: type causer interface {
Cause() error
}
func ErrCode(err error) ErrorCode {
if ce, ok := err.(causer); ok {
return ErrCode(ce.Cause())
}
// ... current ErrCode code
} This would support Just two data points:
|
Your second alternative is not so bad, but I wonder if this belongs in the sqlite package. I think a user can write their own ErrCode wrapper function and use that instead of sqlite.ErrCode, which can do any kind of handling they want. Is that not the case? |
Well, (The I suppose I could reimplement |
|
Oh you did already. :-) |
My fork unwraps errors passed to
ErrCode
:https://github.com/fasterthanlime/sqlite/blob/2c204735769c318990e7b4e133a4f770fea28498/error.go#L341-L352
I'm using https://github.com/pkg/errors throughout my codebases for proper stack traces, etc.
It's not the only Go package that allows that, though, so maybe unwrapping should be pluggable?
Something like:
The signature would be:
In
ErrCode
, there'd be aerrorUnwrapper != nil
check - this should be pretty cheap for folks who don't wrap errors.What do you think? I know it's not ideal, but I can't think of a better solution right now.
If this approach is chosen, the docs should be very clear that only applications should call this, not libraries, and maybe calling
SetErrorUnwrapper
a second time should panic.The text was updated successfully, but these errors were encountered: