Skip to content

Commit

Permalink
Addon loader reports the trace when a module fails to load
Browse files Browse the repository at this point in the history
  • Loading branch information
Yiannis128 committed Feb 4, 2025
1 parent e94e342 commit 41e86e6
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions esbmc_ai/addon_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

import inspect
from typing import Any
from typing_extensions import Optional, override
import traceback
import sys
import importlib
from importlib.util import find_spec
from importlib.machinery import ModuleSpec
import sys
from typing_extensions import Optional, override

from esbmc_ai.base_config import BaseConfig
from esbmc_ai.command_runner import ChatCommand
from esbmc_ai.commands.chat_command import ChatCommand
from esbmc_ai.logging import printv
from esbmc_ai.verifier_runner import BaseSourceVerifier
from esbmc_ai.verifiers.base_source_verifier import BaseSourceVerifier
from esbmc_ai.config import Config, ConfigField


Expand Down Expand Up @@ -93,10 +94,12 @@ def init(self, config: Config, builtin_verifier_names: list[str]):

@property
def chat_command_addon_names(self) -> list[str]:
"""Returns all the addon chat command names."""
return list(self.chat_command_addons.keys())

@property
def verifier_addon_names(self) -> list[str]:
"""Returns all the addon verifier names."""
return list(self.verifier_addons.keys())

def _load_chat_command_addons(self) -> None:
Expand Down Expand Up @@ -149,11 +152,8 @@ def _init_addon_modules(self, mods: list[str]) -> list:
This method will load classes:
* ChatCommands
* BaseSourceVerifier"""
from esbmc_ai.commands.chat_command import ChatCommand
from esbmc_ai.verifiers import BaseSourceVerifier
from esbmc_ai.testing.base_tester import BaseTester

allowed_types = ChatCommand | BaseSourceVerifier | BaseTester
allowed_types = ChatCommand | BaseSourceVerifier

result: list = []
for module_name in mods:
Expand All @@ -168,8 +168,13 @@ def _init_addon_modules(self, mods: list[str]) -> list:
result.append(attr_class())
printv(f"Loading addon: {attr_name}")
except ModuleNotFoundError as e:
print("Addon Loader: Error while loading module: Traceback:")
traceback.print_tb(e.__traceback__)
print(f"Addon Loader: Could not import module: {module_name}: {e}")
sys.exit(1)
except AttributeError as e:
print(f"Addon Loader: Module {module_name} is invalid: {e}")
sys.exit(1)

return result

Expand Down

0 comments on commit 41e86e6

Please sign in to comment.