Skip to content

Commit 3e73c4b

Browse files
committed
chore(toolbox-core): Standardize on ValueError for improved error consistency
This PR updates instances where generic `Exception` objects were thrown in `toolbox-core` to use `ValueError` instead. This aligns with the prevalent use of `ValueError` for argument-related issues elsewhere in the package, leading to more specific, predictable, and robust error handling for consumers of `toolbox-core`.
1 parent 7e5d768 commit 3e73c4b

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ async def load_tool(
176176
# parse the provided definition to a tool
177177
if name not in manifest.tools:
178178
# TODO: Better exception
179-
raise Exception(f"Tool '{name}' not found!")
179+
raise ValueError(f"Tool '{name}' not found!")
180180
tool, used_auth_keys, used_bound_keys = self.__parse_tool(
181181
name,
182182
manifest.tools[name],

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ async def __call__(self, *args: Any, **kwargs: Any) -> str:
184184
req_auth_services = set()
185185
for s in self.__required_authn_params.values():
186186
req_auth_services.update(s)
187-
raise Exception(
187+
raise ValueError(
188188
f"One or more of the following authn services are required to invoke this tool"
189189
f": {','.join(req_auth_services)}"
190190
)
@@ -301,7 +301,7 @@ def bind_params(
301301
)
302302

303303
if name not in param_names:
304-
raise Exception(f"unable to bind parameters: no parameter named {name}")
304+
raise ValueError(f"unable to bind parameters: no parameter named {name}")
305305

306306
new_params = []
307307
for p in self.__params:

packages/toolbox-core/tests/test_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ async def test_load_tool_not_found_in_manifest(aioresponses, test_tool_str):
266266
)
267267

268268
async with ToolboxClient(TEST_BASE_URL) as client:
269-
with pytest.raises(Exception, match=f"Tool '{REQUESTED_TOOL_NAME}' not found!"):
269+
with pytest.raises(ValueError, match=f"Tool '{REQUESTED_TOOL_NAME}' not found!"):
270270
await client.load_tool(REQUESTED_TOOL_NAME)
271271

272272
aioresponses.assert_called_once_with(
@@ -474,7 +474,7 @@ async def test_bind_params_fail(self, tool_name, client):
474474
assert len(tool.__signature__.parameters) == 2
475475
assert "argA" in tool.__signature__.parameters
476476

477-
with pytest.raises(Exception) as e:
477+
with pytest.raises(ValueError) as e:
478478
tool.bind_params({"argC": lambda: 5})
479479
assert "unable to bind parameters: no parameter named argC" in str(e.value)
480480

@@ -605,7 +605,7 @@ async def test_bind_param_fail(self, tool_name, client):
605605
assert len(tool.__signature__.parameters) == 2
606606
assert "argA" in tool.__signature__.parameters
607607

608-
with pytest.raises(Exception) as e:
608+
with pytest.raises(ValueError) as e:
609609
tool.bind_param("argC", lambda: 5)
610610
assert "unable to bind parameters: no parameter named argC" in str(e.value)
611611

packages/toolbox-core/tests/test_e2e.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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-
Exception,
191+
ValueError,
192192
match="One or more of the following authn services are required to invoke this tool: my-test-auth",
193193
):
194194
await tool()

packages/toolbox-core/tests/test_sync_e2e.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def test_run_tool_param_auth_no_auth(self, toolbox: ToolboxSyncClient):
156156
"""Tests running a tool with a param requiring auth, without auth."""
157157
tool = toolbox.load_tool("get-row-by-email-auth")
158158
with pytest.raises(
159-
Exception,
159+
ValueError,
160160
match="One or more of the following authn services are required to invoke this tool: my-test-auth",
161161
):
162162
tool()

0 commit comments

Comments
 (0)