Open matt-phylum opened 1 month ago
I was planning to open another issue for having a DefaultOnError
that works for serialization, but SerializeAs
doesn't have a way to distinguish between errors because the value is unrepresentable and errors because the underlying serializer reported an error. Maybe the fallible (without fraction) versions could to take a type parameter that defines whether an out of range value is skipped or None
or 0.
Thank you for the report. Yes, there is indeed a problem here. The code uses the normal math operations and some as
casts. Fixing all of the instances will be a bit difficult, since the clippy lints for that will lead to many warnings, but not all of them actually being problematic.
Many of the values will not be supported since they cannot be represented internally.
How did you come up with those time values to test? I wonder if you have a list of such strings/timestamps or if you used automated tools.
I do want to fix the issue, but it might take a while. It seems to require some steps
ops::Mul
and ops::Neg
since they can fail. This covers the panics reported here.as
casts. That should address "2262-04-11 23:47:16.854775808 UTC: -9223372036854775808".TimestampSeconds
with a >500ms subsecond part.I used binary search to find these edges between behaviors. I don't know if there's a list of such timestamps, but 9,223,372,036,854,775,807 is the limit of an i64 so those are probably good values to check for any implementation.
TimestampNanoSeconds
has the following serialization behavior:..1385-06-12T00:25:26.290448385Z
: panicoverflow when multiplying duration by scalar
1385-06-12T00:25:26.290448385Z..1677-09-21T00:12:43.145224192Z
: incorrect positive value1677-09-21T00:12:43.145224192Z
: panicattempt to negate with overflow
1677-09-21T00:12:43.145224193Z..2262-04-11T23:47:16.854775808Z
: correct2262-04-11T23:47:16.854775808Z..2554-07-21T23:34:33.709551616Z
: incorrect negative value2554-07-21T23:34:33.709551616Z..
: panicoverflow when multiplying duration by scalar
Not being able to serialize values outside the range
1677-09-21T00:12:43.145224193Z..2262-04-11T23:47:16.854775808Z
is expected since it's serializing to an i64, but if the value is outside that range it should return an error, not panic or return incorrect values.A similar problem exists with
TimestampNanoSecondsWithFrac
:..1385-06-12T00:25:26.290448385Z
: panicoverflow when multiplying duration by scalar
1385-06-12T00:25:26.290448385Z..2554-07-21T23:34:33.709551616Z
: correct2554-07-21T23:34:33.709551616Z..
: panicoverflow when multiplying duration by scalar
TimeStampNanoSecondsWithFrac
should never fail because it is serializing to f64 and f64 can represent much larger values, at the expense of precision.The other
TimeStamp*
serializers are not affected because the range of values that can be represented byDateTime
is smaller than the range of values that can be represented by ani64
.DurationNanoSeconds
andDurationNanoSecondsFrac
also have a similar problem:..18446744073.709551616s
: correct18446744073.709551616s..
: panic:overflow when multiplying duration by scalar
DurationNanoSeconds
should return an error instead of panicking, andDurationNanoSecondsFrac
should never fail.DurationMicroSeconds
andDurationMicroSecondsFrac
fail the same way for18446744073709.551616s..
.18446744073709551.616s..
forDurationMilliSeconds
andDurationMilliSecondsWithFrac
.DurationSeconds
andDurationSecondsWithFrac
are unaffected.