Improve error message when an exception is raised at toolkit import time upon Worker startup (#327)

Upon Worker startup, when an exception raised in a toolkit at import
time, the worker logged output will not display the cause of the
exception, or even that there was an exception raised in the toolkit.

Instead, the worker logs only a not very useful message:

```
 Failed to start Arcade Worker: Could not find tool {tool_name} in module {toolkit_name}.tools.{module_name}
```

This PR improves the logged message by adding the cause of the error.
This commit is contained in:
Renato Byrro 2025-03-24 22:31:49 -03:00 committed by GitHub
parent e7daa1edba
commit d91e417c8d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -243,9 +243,9 @@ class ToolCatalog(BaseModel):
tool_func = getattr(module, tool_name)
self.add_tool(tool_func, toolkit, module)
except AttributeError:
except AttributeError as e:
raise ToolDefinitionError(
f"Could not find tool {tool_name} in module {module_name}"
f"Could not import tool {tool_name} in module {module_name}. Reason: {e}"
)
except ImportError as e:
raise ToolDefinitionError(f"Could not import module {module_name}. Reason: {e}")