Skip to content

Commit

Permalink
fix: show actual function name in NoInitFunctionError
Browse files Browse the repository at this point in the history
Only applies to function-based packages.
  • Loading branch information
MHajoha committed Jan 13, 2025
1 parent 7b88a55 commit b8b9180
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions questionpy_server/worker/runtime/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@


class NoInitFunctionError(Exception):
def __init__(self, module: ModuleType) -> None:
super().__init__(f"The module '{module.__name__}' contains no 'init' function")
def __init__(self, module: ModuleType, init_function_name: str) -> None:
super().__init__(f"The module '{module.__name__}' contains no '{init_function_name}' function")


class ImportablePackage(ABC, Package):
Expand All @@ -51,7 +51,7 @@ def init(self, env: Environment) -> QPyPackageInterface:
main_module = import_module(f"{self.manifest.namespace}.{self.manifest.short_name}")

if not hasattr(main_module, "init") or not callable(main_module.init):
raise NoInitFunctionError(main_module)
raise NoInitFunctionError(main_module, "init")

signature = inspect.signature(main_module.init)
return main_module.init(*(self, env)[: len(signature.parameters)])
Expand Down Expand Up @@ -150,7 +150,7 @@ def init(self, env: Environment) -> QPyPackageInterface:
main_module = import_module(self.module_name)
init_function = getattr(main_module, self.function_name, None)
if not init_function or not callable(init_function):
raise NoInitFunctionError(main_module)
raise NoInitFunctionError(main_module, self.function_name)

signature = inspect.signature(init_function)
return init_function(*(self, env)[: len(signature.parameters)])
Expand Down

0 comments on commit b8b9180

Please sign in to comment.