Skip to content

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

Merged
brendt merged 3 commits into
tempestphp:3.xfrom
mgalexandre:3.x
Jul 15, 2026
Merged

feat(validation): include error messages in ValidationFailed exception message#2203
brendt merged 3 commits into
tempestphp:3.xfrom
mgalexandre:3.x

Conversation

@mgalexandre

@mgalexandre mgalexandre commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

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
Contributor 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

@brendt

brendt commented Jul 10, 2026

Copy link
Copy Markdown
Member

The problem I want solved is this one: you're testing HTTP endpoints with exceptions enabled (a common use case), and you run into a validation error. There's no way to see what's wrong here without making changes to the test code, which is very annoying.

Screenshot 2026-07-10 at 09 54 34

That's the only thing that needs improvement. I don't really care how, but I want to see immediately in the exception message what's wrong

@innocenzi

Copy link
Copy Markdown
Member

Thanks, yeah that's definitely and issue. Then I believe our exception renderer should be responsible for that instead of hijacking the exception message.

Maybe by showing the context for all exceptions, or by special-casing ValidationFailed?

@brendt

brendt commented Jul 13, 2026

Copy link
Copy Markdown
Member

Right but I don't think this is using an exception renderer? It's just PHPUnit showing the exception output during testing — AFAIK

@innocenzi

Copy link
Copy Markdown
Member

Ah, my bad, somehow thought this was our console exception renderer... yeah, not much we can do here if you want to use throwExceptions instead of dd on the response (which is what I do and recommend, btw)

@brendt

brendt commented Jul 14, 2026

Copy link
Copy Markdown
Member

@mgalexandre can you run composer qa locally and fix the failing Mago rule? After that I'll merge :)

@mgalexandre

Copy link
Copy Markdown
Contributor Author

sorry, missed it! it's done :)

@brendt
brendt merged commit a919dec into tempestphp:3.x Jul 15, 2026
74 of 75 checks passed
@brendt

brendt commented Jul 15, 2026

Copy link
Copy Markdown
Member

Thank you :)

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

3 participants