Skip to content

Add a small hint when tasks are called with missing keywords

Calling swh scheduler task add load-git https://example.org/repository.git instead of swh scheduler task add load-git url=https://example.org/repository.git will result in a confusing TypeError being raised by the scheduler.

This change adds a small note to the TypeError pointing at the arguments of swh scheduler task add.

This uses the BaseException.add_note method which was introduced in Python 3.11.

Sadly, I was not able to understand where to plug a test for this.

The result looks like:

ERROR    celery.app.trace:trace.py:270 Task swh.scheduler.tests.tasks.keyword[c6764342-bdda-4d92-9e2d-11e6119ae49b] raised unexpected: TypeError("keyword() missing 1 required keyword-only argument: 'keyword'")
Traceback (most recent call last):
  File "/home/lunar/.pyenv/versions/swh3.11/lib/python3.11/site-packages/celery/app/trace.py", line 477, in trace_task
    R = retval = fun(*args, **kwargs)
                 ^^^^^^^^^^^^^^^^^^^^
  File "/home/lunar/Documents/SWH/swh-environment/swh-scheduler/build/__editable__.swh.scheduler-1.13.1.dev2+g869514d.d20231211-py3-none-any/swh/scheduler/task.py", line 67, in __call__
    raise e
  File "/home/lunar/Documents/SWH/swh-environment/swh-scheduler/build/__editable__.swh.scheduler-1.13.1.dev2+g869514d.d20231211-py3-none-any/swh/scheduler/task.py", line 62, in __call__
    result = super().__call__(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lunar/.pyenv/versions/swh3.11/lib/python3.11/site-packages/celery/app/task.py", line 411, in __call__
    return self.run(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: keyword() missing 1 required keyword-only argument: 'keyword'
Would you have forgotten to write the keywords when calling `swh scheduler task add`?

Merge request reports

Loading