daypack-dev / timere

OCaml date time handling and reasoning suite
MIT License
68 stars 7 forks source link

Produce an informative error message if the local timezone cannot be determined #23

Closed dmbaturin closed 3 years ago

dmbaturin commented 3 years ago

There are situations when the user will get a generic Invalid_argument "CCOpt.get_exn" error message when trying to use Timere_parse.date_time, and it will be impossible to debug without reading the source.

utop # #require "timere.tzdb.none";;
utop # #require "timere.tzlocal.none";;
utop # #require "timere-parse";;

utop # Timere_parse.date_time "1970-01-01 00:00";;
Exception: Invalid_argument "CCOpt.get_exn".

This patch attaches a (hopefully) helpful error message to Invalid_argument.

darrenldl commented 3 years ago

Aha, good point. Thanks!

I'll propagate the fix to the other places where local time zone is queried similarly.

darrenldl commented 3 years ago

Just for reference, I moved your function into Timere.Utils.get_local_tz_for_arg

dmbaturin commented 3 years ago

Thanks, I didn't notice there are more instances of that issue (though I only started playing with the library today, so it's not surprising).

darrenldl commented 3 years ago

Nice! Yeah those cases are in timere itself.

I'm working on Timere 0.3.0 (soon to be released), so there will be some small changes around the API, but things are largely the same otherwise.