-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need help: how to get detailed data about failed validation? #153
Comments
👍 |
Validation failure is expose through exception tree, it's documented in the readme. Basic exceptions are |
@scaytrase thanks for these details. I've seen them. But as for this is very inconvenient to make a new method that will get the exact reason from the failed chain. Moreover, each exception has a different public interface for getting the fail details. Don't you think that will be much better to have something like
after that, we could use it on any kind of failed exception to get some details like keyword, reason, field etc |
How does this |
Apologies, but yes, dumping the whole exception it does indeed include way more helpful information! 🎉 |
@davidyell when you will understand how to get the field name from KeywordMismatch exception please let me know |
@scaytrase I would be very appreciative if you could explain how to get protected compoundIndex from BreadCrumb object without using any kind of reflection |
You have dedicated method |
@jokaorgua I'm using this code. I don't know your use case, but probably you can adjust it to your needs private function getValidationMessage(ValidationFailed $exception): string
{
$ex = $exception->getPrevious();
if ($ex === null) {
return $exception->getMessage();
}
if ($ex instanceof SchemaMismatch) {
if ($ex->dataBreadCrumb() === null) {
return $exception->getMessage();
}
$field = implode('.', $ex->dataBreadCrumb()->buildChain());
return sprintf(
'Validation against spec failed for "%s": "%s"',
$field,
str_replace(['Keyword validation failed: '], '', $ex->getMessage())
);
}
return $exception->getMessage();
} |
@scaytrase thanks. But as for me, the interface should be created for getting errors normally without hacks @canvural thanks! |
Interpreting validation errors is pure userland responsibility. Every project can have it's own implementation and it's own usecase (some use psr-7 validator, some validate raw data, etc). And there is nothing hacky in using fields exampled in the readme (yeah, maybe not that explicitly but anyway) |
Hello. Could anyone recommend or explain how to extract detailed validation errors? Which field, error type, etc?
Thanks.
I'm using such a code in symfony event listener
p.s. I've looked through the code and I do not see any public method to get such an info
The text was updated successfully, but these errors were encountered: