Allow custom ValidationRule implementations to return multiple error messages

Open
#876 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
64/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
rust

Research direction

Start by reading RuleError in laravel::validation and the Rule::failures and validate_matching_rules paths described in the issue. Check how existing custom validation rules return errors and how tests verify multiple messages for one field. Add a public way to return multiple messages, then confirm each appears in the field's error bag.

Written by the indexing model from the issue text.

Description

Need

Some validation rules check a single submitted field against an external verifier or composite policy that can report more than one failure reason at once (for example, CAPTCHA/bot verification APIs returning multiple error-codes, or multi-constraint domain validators).

In PHP Laravel, Illuminate\Contracts\Validation\ValidationRule::validate(string $attribute, mixed $value, Closure $fail) allows calling $fail(...) multiple times for the same field.

Current API gap

In laravel-rust 0.2.0, Rule::failures already returns Result<Vec<String>> internally (used by PasswordRule), and validate_matching_rules adds every message in that Vec to the field's error bag. However, laravel::validation::RuleError only exposes a single-message variant:

pub enum RuleError {
    Invalid(String),
    Failed(crate::Error),
}

So a custom ValidationRule implementation can only emit one validation error message per invocation.

Proposed small API

Either add a multi-message variant or constructor on RuleError (or a Field::reject_all helper):

// Option A: extend RuleError (or keep Invalid(String) and add InvalidMany(Vec<String>))
RuleError::invalid_many(messages: impl IntoIterator<Item = impl Into<String>>) -> Self

or allow Field to collect multiple rejected messages so custom rules can surface all failure reasons cleanly without workarounds.

Dominant language
Rust
Stars
847
Forks
174
Avg merge
5h 40m
Merged PRs (30d)
167

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from laravel/rust-framework

All issues in laravel/rust-framework

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.