-
Notifications
You must be signed in to change notification settings - Fork 697
Proposal: Wrap(nil) should not return nil #174
Comments
I think the package is functioning as intended. In the case above you should return |
@adamzdara consider this thread #90 |
While As the documentation clearly states that the intended behavior is that It is not and cannot be the purpose of this package to help developers ensure that they have not copy-pasted inappropriate code from one line to another. |
All makes sense. Just wanted to make sure that this is intentional. Will fork it for me. Thank you for info. |
I also want to know why you want to return a new error when the function you are calling doesn't? |
This is quite common in, for example, But since one needs the |
ref: this was also discussed on #90. |
My personal conclusion is that while I have a case in mind where I want a nil=>nil behavior, I don't want to spell this I'll only use P.S. compare also to fmt.Errorf("...%w...", err) which always returns an error, matching %v behavior before %w was invented, and matching what you'd expect from "formatting". |
As noted in #90, it is too late to change the behavior and semantics of this package. |
I have recently run several times into issue when I or somebody else copied error handling code from some other case:
and used it for handling of some cases when err is nil and did not changed Wrap() function to New() eg:
...and this is problem because in this case function will terminate with error but returns nil (because errors.Wrap(nil) returns nil). So my proposal here is to change this behaviour in this case to return errors.New(message) instead of nil.
The text was updated successfully, but these errors were encountered: