-
Notifications
You must be signed in to change notification settings - Fork 685
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
Throw a runtime error instead of terminating #580
base: master
Are you sure you want to change the base?
Conversation
This is very difficult logic. Have you ever had a case where this |
I had a case where terminate was called. It has happened multiple times for end users of my program but I haven't reproduced it yet. I may be able to. I think probably the cause was that I was calling make_zoned with either NULL or a string that was not a valid timezone in this code:
Currently I am wrapping this whole section in a try/catch so if it throws instead of terminates then I can log what I was doing when I screwed up |
If you pass in a bad time zone name, you'll get an exception with a So NULL sounds like a more likely culprit. I get a segfault with that. But it didn't make it to the |
I've added checks to the |
I did encounter an assertion error when trying to query the TZDB for dates earlier than the minimum year. |
If you've got a test case I'd be happy to explore it. I did this and got garbage, but no assert: #include "date/tz.h"
#include <iostream>
int
main()
{
using namespace date;
using namespace std;
using namespace std::chrono;
zoned_time zt{current_zone(), sys_days{} - years{50'000}};
auto lt = zt.get_local_time();
cout << lt << '\n';
} |
Sure. With the current current_zone()->get_info(local_seconds(seconds(-4266666666664))); crashes for me with
I encountered this on both Linux and Mac. On Linux, I compile the reproducer with these flags:
|
Thanks much @dkhalanskyjb ! Fixed with 658a3b9 |
Elsewhere in this file if something goes wrong we throw a runtime error. If we also do that here instead of calling std::terminate we can catch it and fix the calling code.