@@ -191,6 +191,58 @@ defmodule Test.Acceptance.ErrorValidationTest do
191191 assert is_binary ( json_error . id )
192192 end
193193
194+ test "RunStepError delegates to inner error with ToJsonApiError implementation" do
195+ inner_error = Ash.Error.Changes.InvalidChanges . exception ( message: "bad input" )
196+
197+ run_step_error =
198+ Reactor.Error.Invalid.RunStepError . exception (
199+ error: inner_error ,
200+ step: % Reactor.Step { name: :test_step }
201+ )
202+
203+ result = AshJsonApi.Error . to_json_api_errors ( nil , nil , run_step_error , :create )
204+
205+ assert [ json_error ] = result
206+ assert json_error . code == "invalid"
207+ assert json_error . title == "Invalid"
208+ assert json_error . detail == "bad input"
209+ end
210+
211+ test "RunStepError delegates to inner Ash wrapper error" do
212+ inner_error =
213+ Ash.Error.Changes.InvalidChanges . exception ( message: "wrapped error" )
214+ |> Ash.Error . to_error_class ( )
215+
216+ run_step_error =
217+ Reactor.Error.Invalid.RunStepError . exception (
218+ error: inner_error ,
219+ step: % Reactor.Step { name: :test_step }
220+ )
221+
222+ result = AshJsonApi.Error . to_json_api_errors ( nil , nil , run_step_error , :create )
223+
224+ assert [ json_error ] = result
225+ assert json_error . code == "invalid"
226+ assert json_error . detail == "wrapped error"
227+ end
228+
229+ @ tag capture_log: true
230+ test "RunStepError falls back to generic error for unknown inner errors" do
231+ inner_error = RuntimeError . exception ( "something unexpected" )
232+
233+ run_step_error =
234+ Reactor.Error.Invalid.RunStepError . exception (
235+ error: inner_error ,
236+ step: % Reactor.Step { name: :test_step }
237+ )
238+
239+ result = AshJsonApi.Error . to_json_api_errors ( Domain , TestPost , run_step_error , :create )
240+
241+ assert [ json_error ] = result
242+ assert json_error . status_code == 500
243+ assert json_error . code == "something_went_wrong"
244+ end
245+
194246 test "Binary error fallback uses UnknownError" do
195247 # Test the binary error handler directly
196248 domain = nil
0 commit comments