Skip to content

Conversation

@swirtSJW
Copy link

@swirtSJW swirtSJW commented Jan 5, 2026

Before
Words with more questions than answeres

After

invalid describedByType

Or
missing url

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

@swirtSJW swirtSJW marked this pull request as draft January 5, 2026 18:33
@swirtSJW swirtSJW marked this pull request as ready for review January 5, 2026 18:57
@swirtSJW swirtSJW self-assigned this Jan 5, 2026
@swirtSJW swirtSJW requested review from Copilot and dafeder January 5, 2026 21:57
Copy link

Copilot AI left a 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 ValidationException constructor 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.

Comment on lines 29 to 37
$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++;
Copy link

Copilot AI Jan 5, 2026

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.

Suggested change
$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++;

Copilot uses AI. Check for mistakes.
$errors = $validationResult->getErrors();
$i = 1;
foreach ($errors as $error) {
$pointer = implode(" -> ", $error->dataPointer());
Copy link

Copilot AI Jan 5, 2026

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.

Copilot uses AI. Check for mistakes.
@swirtSJW
Copy link
Author

swirtSJW commented Jan 5, 2026

This makes use of the methods available https://opis.io/json-schema/1.x/php-validation-result.html

@swirtSJW
Copy link
Author

swirtSJW commented Jan 8, 2026

How it appears when a dataset publish fails
image

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.

Make validation exception more informative.

2 participants