Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Surface underlying exception msg at plugin load #846

Merged
merged 2 commits into from
Aug 22, 2024

Conversation

leondz
Copy link
Collaborator

@leondz leondz commented Aug 21, 2024

we should get the underlying exception into the log.

Example -- traces like this are unhelpful:

2024-08-15 17:14:15,770  INFO  probe queue: probes.topic.WordnetControversial
2024-08-15 17:14:15,770  INFO  probe init: <garak.probes.topic.WordnetControversial object at 0x744e06e45880>
2024-08-15 17:14:15,770  WARNING  Exception failed instantiation of garak.probes.topic.WordnetControversial
2024-08-15 17:14:15,770  WARNING  failed to load probe ValueError('Plugin WordnetControversial not found in probes.topic'):
2024-08-15 17:14:15,770  INFO  run complete, ending
2024-08-15 17:14:15,788  INFO  garak run complete in 3.48s

& there is a typically a more helpful message available:

(garak) 17:14:35 x1:~/dev/garak [feature/topic_probe] $ python
Python 3.12.4 | packaged by Anaconda, Inc. | (main, Jun 18 2024, 15:12:24) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import garak
>>> import garak._config
>>> garak._plugins
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'garak' has no attribute '_plugins'
>>> import garak._plugins
>>> garak._plugins.lo
garak._plugins.load_plugin(  garak._plugins.logging       
>>> garak._plugins.lo
garak._plugins.load_plugin(  garak._plugins.logging       
>>> garak._plugins.load_plugin("probes.topic.WordnetControversial")
WARNING:root:Exception failed instantiation of garak.probes.topic.WordnetControversial
Traceback (most recent call last):
  File "/home/lderczynski/dev/garak/garak/_plugins.py", line 394, in load_plugin
    plugin_instance = klass(config_root=config_root)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lderczynski/dev/garak/garak/probes/topic.py", line 93, in __init__
    wn.config.downloads_directory = _config.transient.cache_dir / "wn" / "downloads"
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: property 'downloads_directory' of 'WNConfig' object has no setter

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/lderczynski/dev/garak/garak/_plugins.py", line 400, in load_plugin
    raise ValueError(
ValueError: Plugin WordnetControversial not found in probes.topic
>>> 

this PR places the underlying message, in this example AttributeError: property 'downloads_directory' of 'WNConfig' object has no setter, into garak.log.

@leondz
Copy link
Collaborator Author

leondz commented Aug 21, 2024

resolves #40

Copy link
Collaborator

@jmartin-tech jmartin-tech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it, one optional minor comment about possibly using logging.exception to allow the exception context to log e. The change would increase the message level from warning to error.

garak/_plugins.py Show resolved Hide resolved
@leondz leondz merged commit ed7ace1 into main Aug 22, 2024
10 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 22, 2024
@jmartin-tech jmartin-tech deleted the feature/log_plugin_load_exceptions branch August 22, 2024 20:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants