Skip to content

feat(validation): include error messages in ValidationFailed exception message#2203

Open
mgalexandre wants to merge 2 commits into
tempestphp:3.xfrom
mgalexandre:3.x
Open

feat(validation): include error messages in ValidationFailed exception message#2203
mgalexandre wants to merge 2 commits into
tempestphp:3.xfrom
mgalexandre:3.x

Conversation

@mgalexandre

@mgalexandre mgalexandre commented Jul 8, 2026

Copy link
Copy Markdown

1. Implements ProvidesContext, exposing the errors as structured context, so they show up in log context via LoggingExceptionReporter and on the development exception page, the same pattern as QueryWasInvalid, EncryptionFailed, and ProcessExecutionWasForbidden.

2. Appends the failures to the message in a human-readable format:

Validation failed for App\User.
- credential: Passkey not valid
- email: Email is already taken; Email domain is not allowed

The message stays untouched (Validation failed.) when there are no error messages.

Fixes #2189

@innocenzi

Copy link
Copy Markdown
Member

I don't think this is the right thing to do, honestly. Appending the JSON-encoded message array seems rough around the edges.

In what situations did you need the message property of the exception to contain the details, and you could not reach for errorMessages?

@mgalexandre

Copy link
Copy Markdown
Author

I've reworked it to do two things:

  • ValidationFailed now implements ProvidesContext (as @NeoIsRecursive suggested on the
    issue), exposing the errors as structured context for logs and the exception page.
  • The message lists the failures in a readable format instead of JSON:
    Validation failed for App\User.
  • email: Email is already taken

@innocenzi

Copy link
Copy Markdown
Member

Right, didn't take a look at the original issue, thanks @mgalexandre

@brendt, in what situations do you need the message to contain the actual errors? I do think the context, as suggested by Neo, is more suited here

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

Successfully merging this pull request may close these issues.

Add validation failures in ValidationFailed message

2 participants