Skip to content

Commit b43409e

Browse files
authored
fix(core)!: Use ValueError for missing 'items' in array parameters (#325)
## Overview This PR improves the developer experience by providing more specific and actionable errors. When a tool parameter of type `array` was defined without its required `items` key, the SDK would raise a generic `Exception`. This made it difficult to distinguish this specific validation failure from other unexpected runtime exceptions. This change corrects the behavior by raising a `ValueError`, which is the semantically appropriate exception for this scenario. The error message has also been slightly updated for consistency. ### Before * Error Type: `Exception` * Error Message: `"Unexpected value: type is 'list' but items is None"` ### After * Error Type: `ValueError` * Error Message: `"Unexpected value: type is 'array' but items is None"` ## Testing The unit test `test_parameter_schema_array_no_items_error` has been updated to reflect these changes.
1 parent 0c0d94e commit b43409e

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __get_type(self) -> Type:
4242
base_type = bool
4343
elif self.type == "array":
4444
if self.items is None:
45-
raise Exception("Unexpected value: type is 'list' but items is None")
45+
raise ValueError("Unexpected value: type is 'array' but items is None")
4646
base_type = list[self.items.__get_type()] # type: ignore
4747
else:
4848
raise ValueError(f"Unsupported schema type: {self.type}")

packages/toolbox-core/tests/test_protocol.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ def test_parameter_schema_array_no_items_error():
8686
name="bad_list", type="array", description="List without item type"
8787
)
8888

89-
expected_error_msg = "Unexpected value: type is 'list' but items is None"
90-
with pytest.raises(Exception, match=expected_error_msg):
89+
expected_error_msg = "Unexpected value: type is 'array' but items is None"
90+
with pytest.raises(ValueError, match=expected_error_msg):
9191
schema._ParameterSchema__get_type()
9292

93-
with pytest.raises(Exception, match=expected_error_msg):
93+
with pytest.raises(ValueError, match=expected_error_msg):
9494
schema.to_param()
9595

9696

0 commit comments

Comments
 (0)