diff --git a/src/droid_sdk/_high_level/messages.py b/src/droid_sdk/_high_level/messages.py index a6c13c0..d71e8ca 100644 --- a/src/droid_sdk/_high_level/messages.py +++ b/src/droid_sdk/_high_level/messages.py @@ -213,9 +213,17 @@ class ErrorEvent: message: str error_type: ErrorType timestamp: datetime = field(default_factory=lambda: datetime.now(timezone.utc)) + error_name: str | None = None + error_detail: FrozenJsonObject | None = None def __post_init__(self) -> None: ensure_aware(self.timestamp, "timestamp") + if self.error_detail is not None: + object.__setattr__( + self, + "error_detail", + freeze_json_object(self.error_detail, where="error detail"), + ) Message: TypeAlias = ( diff --git a/src/droid_sdk/_high_level/streaming.py b/src/droid_sdk/_high_level/streaming.py index ad84895..556c65d 100644 --- a/src/droid_sdk/_high_level/streaming.py +++ b/src/droid_sdk/_high_level/streaming.py @@ -523,6 +523,16 @@ def _convert( message=notification.message, error_type=ErrorType(notification.error_type.value), timestamp=_parse_timestamp(notification.timestamp), + error_name=( + notification.error.name + if notification.error is not None + else None + ), + error_detail=( + notification.error.model_dump(by_alias=True, mode="json") + if notification.error is not None + else None + ), ) ] if isinstance(notification, PermissionResolvedNotification): diff --git a/tests/test_v5_streaming_core.py b/tests/test_v5_streaming_core.py index d3730a7..7899a96 100644 --- a/tests/test_v5_streaming_core.py +++ b/tests/test_v5_streaming_core.py @@ -12,6 +12,7 @@ AssistantMessage, Autonomy, ErrorEvent, + ErrorType, HookExecution, InteractionHandlers, JsonSchema, @@ -1437,3 +1438,44 @@ async def test_dispatcher_registers_through_low_level_handler_slots() -> None: "cancelled": True, "answers": [], } + + +@pytest.mark.asyncio +async def test_error_event_exposes_nested_error_name_and_detail() -> None: + stream = RunStream[None](expected_turn_id="turn", session_id="session") + stream.feed_notification( + { + "type": "error", + "message": "Requested model was not found on the API provider", + "errorType": "Error", + "timestamp": "2026-08-02T11:00:13.647Z", + "error": { + "name": "LLMInvalidRequestError", + "message": "Requested model was not found on the API provider", + }, + } + ) + stream.feed_notification( + { + "type": "error", + "message": "no detail", + "errorType": "Error", + "timestamp": "2026-08-02T11:00:14.000Z", + } + ) + stream.feed_notification(_complete()) + + events = await _collect(stream) + with_detail, without_detail = ( + cast("ErrorEvent", event) for event in events if isinstance(event, ErrorEvent) + ) + assert with_detail.error_type == ErrorType.ERROR + assert with_detail.error_name == "LLMInvalidRequestError" + assert with_detail.error_detail == { + "name": "LLMInvalidRequestError", + "message": "Requested model was not found on the API provider", + } + with pytest.raises(TypeError): + cast("Any", with_detail.error_detail)["name"] = "changed" + assert without_detail.error_name is None + assert without_detail.error_detail is None