-
Notifications
You must be signed in to change notification settings - Fork 533
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
Simplify SerdeError
#1458
Simplify SerdeError
#1458
Conversation
3005e70
to
c5f6189
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1458 +/- ##
==========================================
+ Coverage 92.11% 92.12% +0.01%
==========================================
Files 40 40
Lines 18026 18000 -26
==========================================
- Hits 16604 16583 -21
+ Misses 1422 1417 -5 ☔ View full report in Codecov by Sentry. |
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.
Nice!
src/naive/datetime/serde.rs
Outdated
} | ||
} | ||
} | ||
|
||
/// Create a custom `de::Error` with `SerdeError::InvalidTimestamp`. | ||
pub(crate) fn invalid_ts<E, T>(value: T) -> E |
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.
Three suggestions:
- Maybe this function should be attached to
SerdeError
as a sort of (not quite) constructor, likeSerdeError::invalid()
? - (If not, this function should be defined above
SerdeError
) - Let's move this into the
crate::serde
inline module inlib.rs
?
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.
Maybe this function should be attached to
SerdeError
as a sort of (not quite) constructor, likeSerdeError::invalid()
?(If not, this function should be defined above
SerdeError
)
In my defence, that function looked very different when I started 😆. But I'll keep trying to put things in that order.
I like that with a standalone function only invalid_ts
is public (within the crate), with the type just an implementation detail.
- Let's move this into the
crate::serde
inline module inlib.rs
?
Good suggestion, much more logical place. I added the move as an initial commit.
c5f6189
to
bc03a0f
Compare
While investigating all the CI failures on #1454 I noticed our serde code tries to convert
LocalResult
s to a custom error type.This can all be done in a much simpler way.
I did keep around a simple error enum because it allows reporting the invalid value.
It currently has only one variant for deserialization errors for UNIX timestamps. We could simplify it further, or leave room for adding more formats to deserialize.
Also included is the fix from #1396 for an invalid cast in the
ts_seconds
module forNaiveDateTime
.