utt
utt copied to clipboard
Improve error handling for invalid date input
Improve error messages for invalid dates
Closes #94
Summary
When utt encounters invalid date input—either from command-line arguments or from entries in the log file—it now displays a user-friendly error message instead of a Python traceback.
Problem
Previously, invalid date usage produced unhelpful tracebacks:
$ utt report 324-4242-43
Traceback (most recent call last):
File "/opt/homebrew/bin/utt", line 8, in <module>
sys.exit(main())
...
File "/opt/homebrew/lib/python3.9/site-packages/utt/components/report_args.py", line 74, in parse_absolute_date
return datetime.datetime.strptime(datestring, "%Y-%m-%d").date()
...
ValueError: time data '324-4242-43' does not match format '%Y-%m-%d'
Solution
Added a simple UttError exception class for user-facing errors. Invalid dates now produce clean, actionable messages.
Examples
Invalid date argument
$ utt report invalid-date
error: Invalid date: invalid-date (expected YYYY-MM-DD)
Invalid month argument
$ utt report --month invalid
error: Invalid month: invalid (expected YYYY-MM)
Invalid date in log file
$ utt report
error: Invalid date at line 14: 2025-27-27 17:00 misc: testing
Entries not in chronological order
$ utt report
error: Line 14 not in chronological order: 2025-11-26 17:00 misc: testing
Changes
utt/components/entries.py: AddedUttErrorexception class; catchValueErrorfrom date parsing and convert to user-friendly errorutt/components/report_args.py: Wrapstrptimecalls to raiseUttErroron invalid inpututt/__main__.py: CatchUttErrorat top level and print clean error message
Tests
Added tests for the new error handling:
test_invalid_date_raises_utt_errortest_invalid_month_raises_utt_errortest_invalid_date_raises_value_error(for log file entries)