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

add optional onError callback #364

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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