Skip to content

Optimize exceptions for nested objects #20

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

Merged
merged 2 commits into from
Jul 25, 2020
Merged

Conversation

wol-soft
Copy link
Owner

Currently validation errors for nested objects are handled identically to the errors of the parent object. This may lead to confusing errors:

{
  "id": "Person",
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
    },
    "pet": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
        },
        "age": {
          "type": "integer",
        }
      }
    }
  }
}

Initializing a object like new Person(['name' => false, 'pet' => ['name' => false]]); will throw an exception with the message:

Invalid type for name. Requires string, got boolean
Invalid type for name. Requires string, got boolean

If only one name validation fails the exception isn't helpful to detect whether the name of the main object isn't valid or the name of the nested object.

This PR adds a NestedObjectException wrapping exceptions from nested object instantiation. The NestedObjectException will additionally change the output behaviour of the exception so the exception for the example given above will look like:

Invalid type for name. Requires string, got boolean
Invalid nested object for property pet:
  - Invalid type for name. Requires string, got boolean

…ed exception instead of being merged into top level messages
@coveralls
Copy link

Pull Request Test Coverage Report for Build 306

  • 13 of 13 (100.0%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.004%) to 98.337%

Totals Coverage Status
Change from base Build 304: 0.004%
Covered Lines: 1715
Relevant Lines: 1744

💛 - Coveralls

Repository owner deleted a comment from coveralls Jul 24, 2020
@wol-soft wol-soft merged commit ac2ae33 into master Jul 25, 2020
@wol-soft wol-soft deleted the NestedObjectException branch July 25, 2020 16:28
@wol-soft wol-soft added this to the 0.18.0 milestone Jul 25, 2020
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.

2 participants