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

use thiserror to remove error.rs boilerplate #376

Merged
merged 2 commits into from Oct 15, 2021

Conversation

cosmicexplorer
Copy link
Contributor

Problem

In #296 (comment) we discussed using thiserror to remove some boilerplate in generating Error and From implementations, although we were able to use displaydoc in that PR to impl Display and decided to table the issue pending some ergonomics improvements in the upstream thiserror crate.

Solution

In dtolnay/thiserror#155 we were able to add the necessary internal trait implementation for UnwindSafe boxed dyn Errors to enable using the declarative #[source] attribute from thiserror without needing to introduce an annoying CallbackErrorWrapper to all callsites as #296 had originally attempted. This was quickly merged and released as thiserror version 1.0.30.

Result

As in #287 (comment) where thiserror was first proposed, there's a bit of a balancing act between pulling in an additional dependency + a potentially confusing DSL vs the ability to succinctly describe all of the ways that a variant of our crate::Error can be used at its point of definition. I think that the #[from] and #[source] attributes introduced in this PR make it easier for a client to understand the meaning of an error and also clarify more readily for future developers of this codebase how to generate a meaningful, canonical error.

@jrose-signal jrose-signal merged commit c7c1abb into signalapp:main Oct 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants