Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/droid_sdk/_high_level/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
10 changes: 10 additions & 0 deletions src/droid_sdk/_high_level/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
42 changes: 42 additions & 0 deletions tests/test_v5_streaming_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
AssistantMessage,
Autonomy,
ErrorEvent,
ErrorType,
HookExecution,
InteractionHandlers,
JsonSchema,
Expand Down Expand Up @@ -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