Buggy add-on hooks prevent user actions

Assume this add-on code:

from anki import hooks

def on_notes_delete(collection, note_ids, foobar):
	pass

hooks.notes_will_be_deleted.append(on_notes_delete)

Note that the hook has the wrong signature because only two arguments are passed.

If the user now tries to delete notes, a Python error message “on_notes_delete() missing 1 required positional argument: ‘foobar’” pops up. No note gets deleted and the user has no idea how to fix that because the add-on that caused the problem is not mentioned in the error message.

Even the console output does not help in this case. It looks like this:

Traceback (most recent call last):
  File "concurrent.futures.thread", line 58, in run
  File "aqt.operations", line 107, in wrapped_op
  File "aqt.operations.note", line 40, in <lambda>
  File "anki.collection", line 549, in remove_notes
  File "anki.hooks_gen", line 507, in __call__
TypeError: on_notes_delete() missing 1 required positional argument: 'foobar'

The module that caused the problem is again not visible from the stack trace.

Such errors can mostly be caught at build time.

https://addon-docs.ankiweb.net/mypy.html