Skip to content

fix: prevent struct errors from hitting plain-map normalize_error clause#240

Open
jscheid wants to merge 1 commit intoagentjido:mainfrom
jscheid:fix/normalize-error-struct-dispatch
Open

fix: prevent struct errors from hitting plain-map normalize_error clause#240
jscheid wants to merge 1 commit intoagentjido:mainfrom
jscheid:fix/normalize-error-struct-dispatch

Conversation

@jscheid
Copy link
Copy Markdown
Contributor

@jscheid jscheid commented Apr 1, 2026

The normalize_error clause for %{message: message} matches any map with a :message key — including exception structs. When a struct hit this clause, Map.drop preserved __struct__ and __exception__ in the details, producing a map that masquerades as a struct but has the wrong fields. Downstream JSON encoding then crashes on the malformed map.

Add not is_struct(error) guard so structs dispatch to the dedicated struct clause, which uses Jido.Error.to_map for proper field extraction. Two tests that asserted :execution_error for InvalidInputError now correctly expect :validation_error.

The normalize_error clause for %{message: message} matches any map
with a :message key — including exception structs. When a struct
hit this clause, Map.drop preserved __struct__ and __exception__
in the details, producing a map that masquerades as a struct but
has the wrong fields. Downstream JSON encoding then crashes on
the malformed map.

Add `not is_struct(error)` guard so structs dispatch to the
dedicated struct clause, which uses Jido.Error.to_map for proper
field extraction. Two tests that asserted :execution_error for
InvalidInputError now correctly expect :validation_error.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Leaving this open for now. We added the underlying transport-sanitizer foundation in agentjido/jido_action#134, and I think this jido_ai fix should follow that shared contract instead of broadening the local guard.

As written, the not is_struct(error) change fixes exception dispatch, but it still regresses ordinary non-exception structs with a :message field by sending them to the fallback path. Once the jido_action update is available here, we should revisit this on top of the new sanitizer/transport behavior and tighten the jido_ai side accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants