-
Notifications
You must be signed in to change notification settings - Fork 0
Make validation errors more specific #23
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enhances validation error messages by making them more specific and informative. Instead of generic validation failure messages, the exception now includes detailed information about what failed validation, where it failed (data pointer path), and what the invalid value was.
Key Changes:
- Modified
ValidationExceptionconstructor to append detailed error information to the exception message - Each validation error is formatted with a numbered list showing the data pointer path and the invalid value
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $i = 1; | ||
| foreach ($errors as $error) { | ||
| $pointer = implode(" -> ", $error->dataPointer()); | ||
| $invalidValue = $error->data(); | ||
| if (is_array($invalidValue) || is_object($invalidValue)) { | ||
| $invalidValue = json_encode($invalidValue); | ||
| } | ||
| $message .= "\n {$i}) {$pointer}: {$invalidValue}"; | ||
| $i++; |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable name i is ambiguous for a counter in this context. Consider renaming it to errorNumber or errorIndex to better convey its purpose as an error counter in the formatted output.
| $i = 1; | |
| foreach ($errors as $error) { | |
| $pointer = implode(" -> ", $error->dataPointer()); | |
| $invalidValue = $error->data(); | |
| if (is_array($invalidValue) || is_object($invalidValue)) { | |
| $invalidValue = json_encode($invalidValue); | |
| } | |
| $message .= "\n {$i}) {$pointer}: {$invalidValue}"; | |
| $i++; | |
| $errorIndex = 1; | |
| foreach ($errors as $error) { | |
| $pointer = implode(" -> ", $error->dataPointer()); | |
| $invalidValue = $error->data(); | |
| if (is_array($invalidValue) || is_object($invalidValue)) { | |
| $invalidValue = json_encode($invalidValue); | |
| } | |
| $message .= "\n {$errorIndex}) {$pointer}: {$invalidValue}"; | |
| $errorIndex++; |
| $errors = $validationResult->getErrors(); | ||
| $i = 1; | ||
| foreach ($errors as $error) { | ||
| $pointer = implode(" -> ", $error->dataPointer()); |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The separator ' -> ' is hardcoded. Consider extracting it as a class constant (e.g., POINTER_SEPARATOR) to improve maintainability and make it easier to change the formatting consistently if needed in the future.
|
This makes use of the methods available https://opis.io/json-schema/1.x/php-validation-result.html |

Before

After
Or

Closes #22
Since this is done in the Exception class, this should address all 4 situations in RootedJsonData.php that call this exception and thereby improve all the output in the places where validation can fail in DKAN