-
Notifications
You must be signed in to change notification settings - Fork 40
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
Switch to thiserror or snafu #115
Comments
Note: I believe @samuelburnham would be able/willing to implement this if approved. |
we already use thiserror https://github.com/ipfs-rust/libipld/blob/master/Cargo.toml#L23 an allocation on the error path is actually good for performance as it does less cache thrashing
https://without.boats/blog/failure-to-fehler/
I disagree, have you seen quoting myself as people constantly want to argue with me about this :)
|
errors that need to be handled or recovered from shouldn't really be errors. returning a custom enum or an option is much better in my opinion. |
Regarding no-std support, anyhow seems to work fine but requires using
@dvc94ch do you think this is would be too verbose or okay to add? |
That's for applications with many kinds of errors. And I'm really skeptical about that performance assertion (unless you're dealing with large error types).
Sure, but it makes the error types undiscoverable. That's reasonable in application code, but painful in library code.
I agree but that's not an argument against using it correctly. Importantly, "thiserror" allows building error hierarchies. Usually, one doesn't care about the specific error, but the general kind of error:
With anyhow, determining the general error kind requires downcasting to all possible underlying errors. This becomes a game of whack-a-mole as new error cases pop up over time. |
Backing up a bit, I think my primary motivations are really:
I don't have any concrete use-cases with respect to the rest of my objections. |
I guess if you put it in a function or macro it's not that bad
well, if you return a |
Well, futures are slowly being upstreamed into the standard library. I'd have a similar stance if this library depended on a specific event loop. In the case of error handling, we have (and have had):
At this point, I don't expect anyhow to be the end-all-be-all of error handling. At a minimum, it can't work without allocations, which excludes a class of applications. |
well, with the |
@Stebalien writes:
I'd like to talk about this from a usability (for maintainers of this library, as well as for users), rather then performance. There doesn't seem to be agreement about performance, but perhaps we can find it in regards to usability. Currently So users of the library would then match instead of downcast. Library authors would add a new enum member in case there's a new error class. Would that be all the impact?
@Stebalien: looking at @samuelburnham's branch at https://github.com/yatima-inc/libipld/tree/sb/core-io it looks like no-std support should work even if anyhow is used. Which I guess is the biggest blocker. |
One big difference is that no backtrace is captured. The rust ecosystem hasn't really noticed that there is such a thing because it only works on nightly. This is very unfortunate, but once the rust team manages to get it's act together and stabilize this feature all the error handling in 99% of crates will need to be fixed. It's extremely annoying when debugging someone elses code and I compile with nightly to get a backtrace but they used thiserror. So then I need to go printlning and modifying the code until I find where the error came from. |
It does, it's just a bit annoying (see all the cfgs).
That is a good point, but note that both snafu and thiserror support backtraces as well. But its definitely a more work and less magical. Honestly, I don't feel super strongly about this at the moment. I'm happy to table the discussion till I have concrete data one way or the other. |
libipld currently uses anyhow. Unfortunately:
?
will no longer convert errors intoanyhow::Error
.Encode
norDecode
trait require allocations).The text was updated successfully, but these errors were encountered: