Skip to content

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

@MathieuDerelle

Description

@MathieuDerelle

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 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions