Skip to content

fix: handle wrapper errors with empty inner errors list#423

Merged
zachdaniel merged 1 commit intomainfrom
fix/empty-wrapper-error-crash
Mar 20, 2026
Merged

fix: handle wrapper errors with empty inner errors list#423
zachdaniel merged 1 commit intomainfrom
fix/empty-wrapper-error-crash

Conversation

@barnabasJ
Copy link
Copy Markdown
Contributor

Summary

Fixes #422

When Ash.Error.Forbidden.exception([]) (or any wrapper error with an empty inner errors list) is returned from a generic action, to_json_api_errors flat-maps over [] and produces zero JSON:API errors. This causes the request pipeline to proceed as if no error occurred, ultimately crashing with KeyError: key :result not found in fetch_includes.

  • Added errors != [] guard to the wrapper-unwrapping clause so empty wrappers fall through to the catch-all
  • Added ToJsonApiError protocol implementations for the four wrapper error types (Forbidden, Framework, Invalid, Unknown)
  • Added regression test for a generic action on a PATCH route returning Ash.Error.Forbidden.exception([])

Test plan

  • New test verifies 403 response when generic action returns empty Forbidden error
  • Full test suite passes (347 tests, 0 failures)

When Ash.Error.Forbidden (or Framework, Invalid, Unknown) is raised with
no inner errors, to_json_api_errors flat-mapped over [] and produced zero
JSON:API errors. This caused downstream code to proceed as if no error
occurred, ultimately crashing with KeyError on missing :result assign.

Add a guard (errors != []) to the wrapper-unwrapping clause so empty
wrappers fall through to the catch-all, and add ToJsonApiError protocol
implementations for the four wrapper types so they produce a proper
error response.

Closes #422
@zachdaniel zachdaniel merged commit f417b72 into main Mar 20, 2026
22 of 23 checks passed
@zachdaniel
Copy link
Copy Markdown
Contributor

🚀 Thank you for your contribution! 🚀

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.

Generic action patch error not handled correctly

2 participants