Skip to content

Commit

Permalink
utilize GarakException in cli
Browse files Browse the repository at this point in the history
* when a plugin fails to load raise `GarakException`
* log the exception trace when error handling in `cli`

Signed-off-by: Jeffrey Martin <[email protected]>
  • Loading branch information
jmartin-tech committed Jun 6, 2024
1 parent 3833eef commit 0a378a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion garak/_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import List

from garak import _config
from garak.exception import GarakException

PLUGIN_TYPES = ("probes", "detectors", "generators", "harnesses", "buffs")
PLUGIN_CLASSES = ("Probe", "Detector", "Generator", "Harness", "Buff")
Expand Down Expand Up @@ -151,7 +152,7 @@ def load_plugin(path, break_on_fail=True, config_root=_config) -> object:
"error instantiating module %s class %s", str(mod), plugin_class_name
)
if break_on_fail:
raise Exception(e) from e
raise GarakException(e) from e
else:
return False

Expand Down
8 changes: 5 additions & 3 deletions garak/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def main(arguments=[]) -> None:

from garak import __version__, __description__
from garak import _config
from garak.exception import GarakException

_config.transient.starttime = datetime.datetime.now()
_config.transient.starttime_iso = _config.transient.starttime.isoformat()
Expand Down Expand Up @@ -512,10 +513,11 @@ def main(arguments=[]) -> None:
"💡 try setting --model_type (--model_name is currently set but not --model_type)"
)
logging.info("nothing to do 🤷")
except KeyboardInterrupt:
except KeyboardInterrupt as e:
msg = "User cancel received, terminating all runs"
logging.exception(e)
logging.info(msg)
print(msg)
except ValueError as e:
logging.error(e)
except (ValueError, GarakException) as e:
logging.exception(e)
print(e)

0 comments on commit 0a378a3

Please sign in to comment.