Skip to content
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

Improve error message for top-level schema-validation errors #681

Merged

Conversation

maddenp-noaa
Copy link
Collaborator

Synopsis

Given a.jsonschema

{
  "additionalProperties": false,
  "properties": {
    "n": {
      "type": "integer"
    }
  },
  "required": [
    "n"
  ],
  "type": "object"
}

and a.yaml

x: 42

Old behavior:

$ uw config validate --schema-file a.jsonschema --input-file a.yaml 
[2024-12-19T04:30:37]    ERROR 2 schema-validation errors found in config
[2024-12-19T04:30:37]    ERROR Error at :
[2024-12-19T04:30:37]    ERROR   Additional properties are not allowed ('x' was unexpected)
[2024-12-19T04:30:37]    ERROR Error at :
[2024-12-19T04:30:37]    ERROR   'n' is a required property

Note that Error at : is not useful, and looks like something is missing.

New behavior:

$ uw config validate --schema-file a.jsonschema --input-file a.yaml 
[2024-12-19T04:30:43]    ERROR 2 schema-validation errors found in config
[2024-12-19T04:30:43]    ERROR Error at top level:
[2024-12-19T04:30:43]    ERROR   Additional properties are not allowed ('x' was unexpected)
[2024-12-19T04:30:43]    ERROR Error at top level:
[2024-12-19T04:30:43]    ERROR   'n' is a required property

I think we haven't run into this yet because the driver configs we've been evaluating don't have useful content at the top level; instead, we immediately look under a key (e.g. ungrib:) for a specific driver and validate that. Once again, using uwtools in new contexts points out areas for improvement.

Type

  • Bug fix (corrects a known issue)

Impact

  • This is a non-breaking change (existing functionality continues to work as expected)

Checklist

  • I have added myself and any co-authors to the PR's Assignees list.
  • I have reviewed the documentation and have made any updates necessitated by this change.

@maddenp-noaa maddenp-noaa merged commit debdecb into ufs-community:main Dec 19, 2024
2 checks passed
@maddenp-noaa maddenp-noaa deleted the schema-error-location-fix branch December 19, 2024 14:54
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.

3 participants