Skip to content

Commit 69e7928

Browse files
committed
fix(toolbox-core)!: Throw PermissionError on unauthenticated tool invocation
Earlier a `ValueError` was being thrown. In case of unauthenticated tool calls, a `PermissionError` is more suitable.
1 parent 3d2a5dc commit 69e7928

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

packages/toolbox-core/src/toolbox_core/tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ async def __call__(self, *args: Any, **kwargs: Any) -> str:
200200
for s in self.__required_authn_params.values():
201201
req_auth_services.update(s)
202202
req_auth_services.update(self.__required_authz_tokens)
203-
raise ValueError(
203+
raise PermissionError(
204204
f"One or more of the following authn services are required to invoke this tool"
205205
f": {','.join(req_auth_services)}"
206206
)

packages/toolbox-core/tests/test_e2e.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ async def test_run_tool_no_auth(self, toolbox: ToolboxClient):
147147
"""Tests running a tool requiring auth without providing auth."""
148148
tool = await toolbox.load_tool("get-row-by-id-auth")
149149
with pytest.raises(
150-
Exception,
150+
PermissionError,
151151
match="One or more of the following authn services are required to invoke this tool: my-test-auth",
152152
):
153153
await tool(id="2")
@@ -188,7 +188,7 @@ async def test_run_tool_param_auth_no_auth(self, toolbox: ToolboxClient):
188188
"""Tests running a tool with a param requiring auth, without auth."""
189189
tool = await toolbox.load_tool("get-row-by-email-auth")
190190
with pytest.raises(
191-
ValueError,
191+
PermissionError,
192192
match="One or more of the following authn services are required to invoke this tool: my-test-auth",
193193
):
194194
await tool()

0 commit comments

Comments
 (0)