Skip to content
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 similar #115

Open
expede opened this issue Jul 12, 2023 · 3 comments
Open

Switch to thiserror or similar #115

expede opened this issue Jul 12, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@expede
Copy link
Member

expede commented Jul 12, 2023

NB: Feature requests will only be considered if they solve a pain or present a useful refactoring of the code.

Summary

Problem

rs-ucan today doesn't provide descriptive errors

Impact

It's hard to debug when integrating rs-ucan into applicatons, and makes it difficult to provide good error messages to users.

Solution

Switch from anyhow to thiserror or similar. The general guidance ([even metioned in the anyhow README) is that anyhow is great for applciations (where you don't expect to recover the error), and thiserror is best for libraries because it gives you more detail about what went wrong.

The trade off is that thiserror involves more manual threading through of error structs.

Detail

@blaine ran into this while building the Fission server.

Coda

First off, thank you so much to the miantainers of rs-ucan for the work thus far. anyhow was probably the fastest & most pragmatic way to get things running.

@cdata
Copy link
Member

cdata commented Jul 13, 2023

Sounds good to me, contributions welcome here!

@cdata cdata added the enhancement New feature or request label Jul 13, 2023
@cdata
Copy link
Member

cdata commented Jul 13, 2023

Anecdotally, we use thiserror in Noosphere (so soft preference for that crate)

@FintanH
Copy link

FintanH commented Jun 11, 2024

Heya 👋 I'd be down for taking on this task to help out so I can peruse the library while also helping out 😊

Before I would start I would ask what style of error management you would prefer in the library. On one end of the spectrum we could provide the kitchen-sink Error which captures all the error variants in a global error type, an example of this would be git2::Error. On the other end of the spectrum, we have very fine-grained errors types, essentially one for each function (this kind of approach is described in this post). Then somewhere in the middle, errors are grouped by some common components and aggregated in parent components, for example, mod foo and mod bar have their own Error types, and then top-level functions in lib.rs would have an Error type that has variants for foo::Error and bar::Error. Choosing what granularity in this scenario is probably the trickier part and requires on-the-fly judgement :)

In an ideal world, I'd go for the fine-grained approach as much as possible but tend to end up writing error code in the middle of the above spectrum. I don't really like the kitchen-sink error because it becomes really hard to tell where your errors are coming from.

Let me know what you think 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants