Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveInteraction::Errors#merge! does not merge custom options #554

Closed
danila opened this issue Jan 19, 2023 · 4 comments
Closed

ActiveInteraction::Errors#merge! does not merge custom options #554

danila opened this issue Jan 19, 2023 · 4 comments

Comments

@danila
Copy link

danila commented Jan 19, 2023

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):

> result = resolve_activity_specific_interaction.run(user: user, activity: activity);
> result.errors
=> #<ActiveInteraction::Errors [#<ActiveModel::Error attribute=base, type=Challenge is completed, options={:code=>"activity_completed"}>]>
> errors
=> #<ActiveInteraction::Errors []>
> errors.merge!(result.errors)
=> #<ActiveInteraction::Errors [#<ActiveModel::Error attribute=base, type=Challenge is completed, options={}>]>

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.

@AaronLasseigne
Copy link
Owner

From what you've said that sounds like a bug. I'll have to do a bit of exploring to see what I can figure out.

@danila
Copy link
Author

danila commented Feb 7, 2023

@AaronLasseigne thanks for looking into this! Since it sounds like a bug, I could also investigate this and suggest a possible fix in a PR, wdyt?

@AaronLasseigne
Copy link
Owner

A PR would be great!

@AaronLasseigne
Copy link
Owner

This is fixed in the 5.3.0 release. Let me know if you have any issues.

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

No branches or pull requests

2 participants