You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello there!
I stumbled upon a behavior that I find unobvious. Although I'm not sure I cook errors the right way they are designed to be used. Please feel free to correct me if I'm wrong. And if not, I'll be happy to introduce missing (from my pov) logic.
I use errors in the following style: errors.add(:base, "Activity is completed", code: "activity_completed")
So that I use the type part of an error as a holder for an error message, and then I add a code to the options hash. In case I use composition and want to merge errors of nested interaction with the errors from the current context, the nested error options are ignored, so I end up losing nested error codes. From what I see in the sources, the reason is type a String and therefore merge_detail! which considers options is not used during merging. Like that (execution happens inside interaction):
Hello there!
I stumbled upon a behavior that I find unobvious. Although I'm not sure I cook errors the right way they are designed to be used. Please feel free to correct me if I'm wrong. And if not, I'll be happy to introduce missing (from my pov) logic.
I use errors in the following style:
errors.add(:base, "Activity is completed", code: "activity_completed")
So that I use the
type
part of an error as a holder for an error message, and then I add a code to the options hash. In case I use composition and want to merge errors of nested interaction with the errors from the current context, the nested error options are ignored, so I end up losing nested error codes. From what I see in the sources, the reason istype
aString
and thereforemerge_detail!
which considers options is not used during merging. Like that (execution happens inside interaction):And I expected that
errors.merge!(result.errors)
would have produced#<ActiveInteraction::Errors [#<ActiveModel::Error attribute=base, type=Challenge is completed, options={:code=>"activity_completed"}>]>
A possible workaround that would suit me could be an interface for
ActiveInteraction::Errors
which would allow pushing existing errors objects.I will be very grateful for the clarifications.
The text was updated successfully, but these errors were encountered: