Page MenuHome

Raise a more explanatory exception when failing to enable an Addon module from a directory containing a '.'
AbandonedPublic

Authored by Rune Morling (ermo) on Oct 28 2019, 9:33 PM.

Details

Summary

As a followup to rB9267e6275cc9 I have tried my hand at editing the message passed to the ModuleNotFoundError exception which is now raised when failing to enable an Addon module from a directory containing a '.'

This has the side benefit of addressing T65360 as per @Philipp Oeser (lichtwerk)'s comment:

(...) to check inside the .zip if we would find offending package names (...) and tell the user that the installation failed.

Original exception message:

Traceback (most recent call last):
  File "/usr/x86_64-pc-linux-gnu/share/blender/2.80/scripts/modules/addon_utils.py", line 351, in enable
    mod = __import__(module_name)
ModuleNotFoundError: No module named 'Precision-Drawing-Tools-1'

Modified exception message:

Traceback (most recent call last):
  File "/usr/x86_64-pc-linux-gnu/share/blender/2.80/scripts/modules/addon_utils.py", line 351, in enable
    mod = __import__(module_name)
ModuleNotFoundError: Addon directory names may not contain dots ('.'): Precision-Drawing-Tools-1.1.5-rc2

Diff Detail

Event Timeline

Rune Morling (ermo) edited the summary of this revision. (Show Details)
Rune Morling (ermo) edited the summary of this revision. (Show Details)Oct 28 2019, 9:39 PM

I'd rather not interpret Python's exceptions, the current error here with io.anim_camera.py states:

ModuleNotFoundError: No module named 'io.anim_camera'; 'io' is not a package

Which shows there is an issue with the name, as users shouldn't be naming their addons manually, this is a developer issue which Python developers should be able to manage.

Another solution could be to add a print() statement like in the if clause above? This wouldn't change the exception propagated to the user, but it'd still offer some more context?

I realise that there has a to be a boundary beyond which the answer is simply "go study Python and become enlightened". I'm just suggesting that it wouldn't hurt to somehow remind new Blender add-on developers that module names may only contain one period when the add-on is a file and exactly zero periods when the add-on is a directory?

Would you be at all open to consider a print() statement solution?