-
Notifications
You must be signed in to change notification settings - Fork 185
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
Replace thiserror with displaydoc #863
Conversation
fastmod "thiserror = .*$" "displaydoc = { version = \"0.2.3\", default-features = false }"
fastmod thiserror::Error displaydoc::Display
fastmod "derive\(Error" "derive(Display"
Run `find . -name *.rs | xargs -I{} gawk -f replace.awk -i inplace {}` with ```awk BEGIN { a = 0; enum = "" } /#\[derive\(Display/ { a = 1 } match($0, /enum ([a-zA-Z]+)/, arr) { enum = arr[1] } { print } /^}/ && a == 1 { print "\nimpl std::error::Error for " enum " {}\n" a = 0 } ```
Codecov Report
@@ Coverage Diff @@
## main #863 +/- ##
==========================================
- Coverage 74.38% 74.35% -0.03%
==========================================
Files 206 206
Lines 13033 13042 +9
==========================================
+ Hits 9694 9697 +3
- Misses 3339 3345 +6
Continue to review full report at Codecov.
|
InvalidTimeZoneOffset, | ||
} | ||
|
||
impl std::error::Error for DateTimeError {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue: when #[error(transparent)]
or #[from]
is used, I think thiserror
properly implements the source
function of std::error::Error
. Should we do that here, too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're not using .source()
and it's not super important (this is, like I said, some of the "old error handling" stuff that will eventually be replaced)
UnknownSyntax(SyntaxOption), | ||
} | ||
|
||
impl std::error::Error for Error {} | ||
|
||
impl From<serde_json::error::Error> for Error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: do we have a path forward for getting rid of these From
impls again in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's easy to write another custom derive for From
for stuff like this.
But also, manually writing From impls like this is super common.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but make CI happy first :)
Yep, on it, |
Fixes #860
I added a displaydoc feature that makes it more suited to our use case.
I've tried to include code transformation commands (fastmod, awk) in the commit message where I used them.
We have a couple downsides of this change:
From
impls need to be manually written when required (not a huge deal)impl std::error::Error for FooError {}
is needed everywhere. We could follow this up with a custom derive but that seems like overkill to meHowever, this change is required to sensibly support
no_std
.