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

is there a way to prefix errors before merging them ? #165

Open
MathieuDerelle opened this issue Dec 19, 2023 · 0 comments
Open

is there a way to prefix errors before merging them ? #165

MathieuDerelle opened this issue Dec 19, 2023 · 0 comments

Comments

@MathieuDerelle
Copy link

MathieuDerelle commented Dec 19, 2023

Im nesting mutations like so :

class ParentMutation < Mutations::Command
  required do
    hash :a do
       model :b, class: Hash
    end
  end
  
  def validate
    validation_outcome = ChildMutation.validate(a[:b])
    return if validation_outcome.success?
    
    merge_errors(validation_outcome.errors)
  end
  
  def execute
    # ... some code
    ChildMutation.run!(a[:b])
    # ... some code
  end
end

class ChildMutation < Mutations::Command
  required do
    string :c
  end
end

(its an extremely simplified version)

when running ParentMutation.run(a: { b: {} }).errors, im getting errors as follow

{
    :c => #<Mutations::ErrorAtom:0x00007fd5a4540ca0 @key=:c, @symbol=:required, @message=nil, @index=nil>
}

but I'd like to prefix the errors with a.b during merge_errors to get something like this instead

{
    'a.b.c' => #<Mutations::ErrorAtom:0x00007fd5a4540ca0 @key=:c, @symbol=:required, @message=nil, @index=nil>
}

or

{
  :a => {
    :b => {
      :c => #<Mutations::ErrorAtom:0x00007fd5a4540ca0 @key=:c, @symbol=:required, @message=nil, @index=nil>
    }
  }
}

Is it possible ?

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

1 participant