flarum/framework · warning · ValidationException

ValidationException (messages from validator)

Error message

ValidationException (messages from validator)

What it means

AbstractValidator::assertValid builds a Laravel validator from the subclass's rules via makeValidator and throws ValidationException carrying the validator whenever any rule fails. This is Flarum's central validation mechanism for user input (usernames, emails, tags, etc.), so the message set mirrors Laravel's validation messages.

Solutions

  1. Catch ValidationException and inspect getErrors()/errors() for the per-attribute messages, then correct the payload and retry.
  2. Pre-validate attributes client-side against the same rules (required fields, email format, length limits) before calling the endpoint.
  3. Check your validator subclass rules — overly strict rules (e.g. unique constraints with soft-deleted rows) may need adjustment.

Example fix

// before: assuming success
$user = $this->users->create($data);

// after
catch (ValidationException $e) {
    $errors = $e->getErrors()->toArray();
    return response()->json(['errors' => $errors], 422);
}
Defensive patterns

Strategy: try-catch

Validate before calling

// mirror required fields before calling assertValid
$missing = array_filter($rules, fn($r, $k) => str_contains($r, 'required') && !isset($attributes[$k]), ARRAY_FILTER_USE_BOTH);
if ($missing) { throw new InvalidArgumentException('Missing: ' . implode(',', array_keys($missing))); }

Try / catch

try {
    $validator->assertValid($attributes);
} catch (ValidationException $e) {
    foreach ($e->errors()->all() as $message) { /* surface to user */ }
}

Prevention

When it happens

Trigger: Any Flarum validator subclass's assertValid(array $attributes) receiving attributes that break configured rules — e.g. registering a username that's already taken, invalid email format, missing required fields, or attributes exceeding max lengths.

Common situations: API clients (POST /api/users, tag creation, profile edits) submitting payloads violating rules; extensions adding rules that existing stored data no longer satisfies; locale files missing so messages render as keys.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of flarum/framework@4b939f6853 (2026-09-15). Data as JSON: /api/errors/02ae35d97da37551. Report an issue: GitHub.

Appendix: source

Thrown at framework/core/src/Foundation/AbstractValidator.php:53

    ) {
    }

    public function addConfiguration(callable $callable): void
    {
        $this->configuration[] = $callable;
    }

    /**
     * Throw an exception if a model is not valid.
     *
     * @throws ValidationException
     */
    public function assertValid(array $attributes): void
    {
        $validator = $this->makeValidator($attributes);

        if ($validator->fails()) {
            throw new ValidationException($validator);
        }
    }

    /**
     * Whether to validate missing keys or to only validate provided data keys.
     */
    public function validateMissingKeys(bool $validateMissingKeys = true): static
    {
        $this->validateMissingKeys = $validateMissingKeys;

        return $this;
    }

    public function prepare(array $attributes): static
    {
        $this->laravelValidator ??= $this->makeValidator($attributes);

        return $this;

View on GitHub (pinned to 4b939f6853)