Repository navigation
Conversation
OneOfValidator, AnyOfValidator and PropertyNamesValidator added some of their own errors straight to the error list instead of calling ExecutionContext.addError. Those errors skipped fail fast, and an ExecutionContext that overrides addError never saw them. - oneOf: the error for zero or several matching branches now goes through addError. With fail fast, a later error no longer replaces it. - oneOf and anyOf: the discriminator error for a value that maps to no schema now goes through addError. With fail fast, a later error no longer replaces it. In oneOf the check moves after the branch loop, once the error list is restored, as it already was in anyOf. - propertyNames: the property name errors now go through addError once the inner schema has run. The inner schema runs with fail fast off, so fail fast returns the propertyNames error rather than the inner error, such as maxLength. With fail fast, it stops at the first invalid name. The branch errors that oneOf and anyOf report after their own error were already reported through addError when the branches ran, so they are still added to the list directly.
|
Review of head The issue is real. I ran master and this branch with fail fast on:
All 8 new tests fail on master and pass here. The full suite passes: 10954 tests, 0 failures. Findings, most-severe first. 1. 2. 3. Discriminated 4. CHANGELOG ( 5. Duplicated test fixtures ( 6. Test gaps ( |
With fail fast on, a keyword error throws FailFastAssertionException. Schema.validate catches it and returns the error, but the walk entry points did not, so walk threw instead of returning the result. This affected type, and now oneOf, whose error goes through addError. walkAtNodeInternal, which every walk entry point and walkAtNode go through, now catches it as validate does.
A failing anyOf added its branch errors straight to the error list. Its branches run with fail fast off, so with fail fast on the anyOf failure did not stop the evaluation: a later error replaced it, and anyOf alone returned every branch error rather than the first. With fail fast on, a failing anyOf now adds its branch errors and throws FailFastAssertionException with the first one, or the first error of the branch the discriminator selects, as addError does. The branch errors already went through addError when the branches ran, so an ExecutionContext that overrides addError does not see them again. Without fail fast, the branch errors are added as before. Issue1276Test characterised the old result, in which anyOf returned every leaf error even with fail fast, as the BOOLEAN and FLAG formats turn on. It now expects one error with fail fast for anyOf as for oneOf.
With a discriminator, a failing oneOf reported its own error and then the errors of the branch the discriminator selects. Now that its own error goes through addError, fail fast stops there, so it returns only the oneOf error where it used to return the branch errors too. A failing anyOf has no error of its own and returns the first error of that branch. Each keyword returns its first error, so they differ. Added tests that pin both results, with and without fail fast, and described the change in the CHANGELOG.
Linked the entry to the pull request, as its neighbours link theirs, and listed what changes for callers: the propertyNames error now replaces the error of its inner schema, such as maxLength or pattern, and its /<property> location; anyOf and walk stop at the first error with fail fast; and the discriminated oneOf result with fail fast.
… test AnyOfValidatorTest and OneOfValidatorTest held the same discriminator schema, inputs and tests, differing only in the keyword. They now live in AlternativeDiscriminatorTest, which runs each test over oneOf and anyOf and states the expected errors per keyword where they differ.
Added propertyNames tests for an object with more than one invalid property name, with and without fail fast, and for walk with fail fast. With fail fast, propertyNames returns the error of the first invalid name whether or not it stops checking names, since addError throws on that error. The test therefore records what reaches an ExecutionContext that overrides addError: only the first name's maxLength error, which fails if the inner schema goes on to check the other names. The walk test for oneOf and the failing anyOf tests came with their fixes.
|
Review of head 1. No test of fail-fast 2. Walk and 3. 4. 5. CHANGELOG placement ( 6. Eighth copy of the disable/restore fail-fast block ( 7. Duplicated fixture ( |
OneOfValidator,AnyOfValidatorandPropertyNamesValidatoradded some of their own errors straight to the error list instead of callingExecutionContext.addError. Those errors skipped fail fast, and anExecutionContextthat overridesaddErrornever saw them.oneOf: the error for zero or several matching branches now goes throughaddError. With fail fast, a later error no longer replaces it.oneOfandanyOf: the discriminator error for a value that maps to no schema now goes throughaddError. With fail fast, a later error no longer replaces it. InoneOfthe check moves after the branch loop, once the error list is restored, as it already was inanyOf.propertyNames: the property name errors now go throughaddErroronce the inner schema has run. The inner schema runs with fail fast off, so fail fast returns thepropertyNameserror rather than the inner error, such asmaxLength. With fail fast, it stops at the first invalid name.The branch errors that
oneOfandanyOfreport after their own error were already reported throughaddErrorwhen the branches ran, so they are still added to the list directly.Tests
Each validator gets two tests, both failing before the change:
ExecutionContextthat overridesaddErrorsees every returned errormvn verifypasses: 10,954 tests, 0 failures.