Skip to content

Comments

add optional onError callback#364

Open
osi-jehrlich wants to merge 1 commit intotdegrunt:masterfrom
osi-jehrlich:on-error-callback
Open

add optional onError callback#364
osi-jehrlich wants to merge 1 commit intotdegrunt:masterfrom
osi-jehrlich:on-error-callback

Conversation

@osi-jehrlich
Copy link
Contributor

This is an enhancement request + PR in one:

The goal is to stop validating after 200 errors. Instead of hard-coding that number, and instead of a specific option like throwAfter: 200, a generic onError callback can be the building block to enable this.

To stop after 200 errors we could do something like this: onError: () => { if (++count >= 200) { throw ... } }.

@awwright
Copy link
Collaborator

awwright commented May 8, 2022

I like the idea of using a callback, but we just have to make sure that usage inside "not" and other "non-cascading" keywords doesn't impact the root call. We want most errors to bubble all the way up, just not that one.

@awwright
Copy link
Collaborator

Today I'll push a patch release for #363 with no additional changes. Then sometime next week I'll push a feature release that re-uses the errors array, and adds the "onError" callback. Cascading the errors array doesn't seem to save that much memory, but it ensures that non-cascading sub-schemas ("not", "if", "oneOf" etc.) are properly isolated from their parent, which is necessary to add this feature.

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