Skip to content

Improve constraint violation parameter output #200

@Blacksmoke16

Description

@Blacksmoke16

Non-scalar parameters are currently simply converted to strings via their default #to_s method. This leaves for less than ideal outputs in some cases depending on what the value is. E.g.

constraint = AVD::Constraints::Choice.new(
  ["one", "two", "three"],
  message: "{{ value}} is not one of {{ choices }}."
)

puts AVD.validator.validate "four", constraint
# four:
#     {{ value}} is not one of ["one", "two", "three"]. (code: c7398ea5-e787-4ee9-9fca-5f2c130614d6)

It might not be a bad idea to have a bit more robust/predictable output for these parameters. Can maybe reference https://github.com/symfony/validator/blob/6.2/ConstraintValidator.php#L76-L145.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions