-
Notifications
You must be signed in to change notification settings - Fork 545
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
Parsed
documentation and error handling
#1418
Conversation
ddfb12a
to
dddd56f
Compare
The |
I think those are separate points. One benefit of using Another point is that iterative macros (like parsed!) are not trivial to wrap your head around (compared to the straight forward Eventually if all |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 0.5.x #1418 +/- ##
==========================================
- Coverage 94.28% 93.32% -0.97%
==========================================
Files 37 37
Lines 16969 15959 -1010
==========================================
- Hits 15999 14893 -1106
- Misses 970 1066 +96 ☔ View full report in Codecov by Sentry. |
dddd56f
to
62fe7df
Compare
ac92b04
to
3540ede
Compare
dcfe74e
to
7745c97
Compare
The git commits are interesting. Parsing was introduced with v0.2.0. The same commits that introduced
We are already doing checks, and doing magnitudes more work than these checks when parsing. I'm not concerned this changes anything in terms of efficiency.
It will allow the parsing code, that uses
It takes little effort for us to supply this extra information; we only need to move these range checks to happen earlier in
We still need to check most things. The check that all fields are consistent with each other can only happen at the end. Doing the check after any parsed field is wasteful. And trying to resolve fields to a date/time/offset is also wasteful until we know we have all the fields that we are going to get. |
7745c97
to
d074166
Compare
ebf35b6
to
8f1bb55
Compare
8f1bb55
to
8fe856a
Compare
I intend to split this PR in multiple parts, but opened it for discussion on how best to do so.
The main goal is to move all range validation to the
Parsed::set_*
methods.This is preliminary work to convert this type and the parsing methods to our new
Error
type (cc @Zomtir).It has four pieces:
1. For the 0.4 branch
We have two small bugs in our implementation of
Parsed
:OUT_OF_RANGE
if the year value didn't match with values ofyear_div_100
oryear_mod_100
. It should returnIMPOSSIBLE
instead.2. Documentation
I have added documentation to all methods describing their error causes. And the
Parsed
type got some documentation describing why it exists (the resolution algorithm), and an example of how to use it. Partly taken from the blog post before chrono 0.2: https://lifthrasiir.github.io/rustlog/worklog-2015-02-19.html3. Goal: move all range validation to the
set_*
methodsThe goal of this PR was to move all range validation to the
set_*
methods.Currently the
set_*
methods do a partial range check, or just a checked cast, and theto_*
methods do the complete range checks. Doing them all in theset_*
methods will allow us to give more a precise error when we convert the parsing code to the new error type. (It can then return the position in the format string where an invalid value appeared.)4. Nice to have
It would be nice if the
to_
methods can rely on the range checks performed byset_*
.But currently they can't because the fields of
Parsed
are public.Making the fields private seems like a good thing to do for this type in general. It involves:
format::parse
to use theset_*
methods.As a clean solution to replacing the macro's I changed the return type of the
set_*
methods to be usable as a builder pattern.How to split
set_*
methods to the 0.4 branch. We already document they do range checks, only that they may not have been precise and delay the error until theto_*
methods.set_*
methods to a builder pattern, making the fields ofParsed
private and simplifying theto_*
methods require 0.5. None of those are strictly necessary, but they do improve our error story and are nice to have.