pimutils / pimutils/khal

daterange parsing error should include a hint

Open
#786 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

type: enhancement
Dominant language
Python
Stars
3.1k
Forks
233
Avg merge
1h 44m
Merged PRs (30d)
1

Description

If I use the wrong formatting to ask for a list of events on some given future data, eg khal list 18-june-2018 10d I get a heap of errors that end with the very clear notice that khal wasn't able to parse the date range I provided:

amanda@mona:~$ khal list 18-june-2018 10d
Traceback (most recent call last):
  File "/usr/local/bin/khal", line 11, in <module>
    sys.exit(main_khal())
  File "/home/amanda/.local/lib/python3.5/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/amanda/.local/lib/python3.5/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/amanda/.local/lib/python3.5/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/amanda/.local/lib/python3.5/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/amanda/.local/lib/python3.5/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/amanda/.local/lib/python3.5/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/amanda/.local/lib/python3.5/site-packages/khal/cli.py", line 323, in klist
    env={"calendars": ctx.obj['conf']['calendars']}
  File "/home/amanda/.local/lib/python3.5/site-packages/khal/controllers.py", line 226, in khal_list
    default_timedelta_datetime=conf['default']['timedelta'],
  File "/home/amanda/.local/lib/python3.5/site-packages/khal/controllers.py", line 142, in start_end_from_daterange
    default_timedelta_datetime=default_timedelta_datetime,
  File "/home/amanda/.local/lib/python3.5/site-packages/khal/utils.py", line 438, in guessrangefstr
    raise ValueError('Could not parse `{}` as a daterange'.format(daterange))
ValueError: Could not parse `('18-june-2018', '10d')` as a daterange

Ideally khal would not show me the full traceback, but would be more precise about what it is looking for in a date. Something like:

ValueError: Could not parse ('18-june-2018', '10d') as a daterange -- "18-june-2018" is not a valid date. Khal expects dates in the format "18-may" Check the usage documentation for more examples of START and END date formats.

If I give a bad DELTA, eg. khal calendar 18-jun 1w I get a slightly different error, but it doesn't tell me that the delta is the problem:

critical: Could not parse ('18-jun', '1w') as a daterange

Something like "10w does not appear to be a valid END or DELTA value" would clue me into the fact that khal doesn't do weeks.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with khal/utils.py at guessrangefstr and trace its callers through controllers.py at start_end_from_daterange. Reproduce the invalid date and delta examples first, then check the usage documentation for the expected formats. Done means date-range errors identify whether the date or delta is invalid and provide a useful hint instead of an unhelpful traceback.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.