-
-
Notifications
You must be signed in to change notification settings - Fork 611
fix(core): improve error handling for comparing invalid dates #6120
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
Conversation
tests/Utils.test.ts
Outdated
| expect(compareObjects(new Date('2024-10-01T08:54:48.651Z'), new Date('2024-10-01T08:54:48.651Z'))).toBe(true); | ||
| expect(compareObjects(new Date('2024-10-01T08:54:48.651Z'), new Date('2024-10-01T08:54:48.676Z'))).toBe(false); | ||
| expect(compareObjects(new Date('2024-10-01T08:54:48.651Z'), new Date(NaN))).toBe(false); | ||
| expect(compareObjects(new Date(NaN), new Date(NaN))).toBe(true); |
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.
i would focus more on how this happened instead of supporting it on this low level helper. this feels like you are fixing it on wrong level.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #6120 +/- ##
========================================
Coverage 99.79% 99.79%
========================================
Files 264 264
Lines 18825 18870 +45
Branches 4685 4469 -216
========================================
+ Hits 18786 18831 +45
Misses 39 39 ☔ View full report in Codecov by Sentry. |
|
maybe we could revert those recent changes, since they were added because of how |
@B4nan You were right! We should not fix this the way I did, or even not fix it at all. I was initially trying to replicate the behavior of In After more thought, I think it is best to throw an error and explain that this behavior is unsupported. There are no "invalid dates" in the BSON format, so I don't think we should handle that at all. In the last commit I pushed on this PR, I changed the function to throw an exception when we encounter such a case. This does not "fix" anything but makes it explicit that there is an issue with the user code. Investigating this made me find an issue in the codebase I'm working on, so this is a good thing 🙏 |
Yes probably! Let's settle on the desired behavior for updates with invalid dates, then with all the tests we've added recently, it should be safe to try 👌 |
|
I don't mind explicit exceptions as you did. Perf wise, I would rather store the |
|
Good point! done |
This PR fixes an issue I introduced in #6094
Using
toISOString()on an invalid date throws a RangeError exception. We should test if the date is valid before comparing it withtoISOString().