Allow schema to still validate even if AJV fails#1269
Merged
datho7561 merged 1 commit intoJun 5, 2026
Conversation
AJV can throw a RangeError (max recursion) when trying to resolve the metaschema even if the schema is valid
4dd1ea5 to
93ae44d
Compare
datho7561
reviewed
Jun 5, 2026
| valid = validator(toValidate); | ||
| } catch (e) { | ||
| // AJV overflows on recursive/cyclic schemas; attempt to degrade gracefully | ||
| console.warn(l10n.t("Schema '{0}' could not be fully validated: {1}", loc, e.message)); |
Contributor
There was a problem hiding this comment.
It might be better to report this as a warning or error on the text document and provide translations for this message, but I think this is good for now.
datho7561
approved these changes
Jun 5, 2026
Contributor
datho7561
left a comment
There was a problem hiding this comment.
Works well to fix the bug. Thanks, Heather!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I was trying to track down yet another StackOverflow error in AJV that wasn't fixed in #1260. But honestly, I would like to see this code be slightly more resilient to AJV since having a schema that isn't valid against the metaschema still is possible to do a lot of checking that is very valuable.
What does this PR do?
This captures a nasty RangeError (
Maximum call stack size exceeded) that is possible in AJV when you have multiple local $ref's recursively referencing each other (while their $id has a full uri).In that case, it just warns to the console and allows normal validation to continue. (note that having a schema resolution error causes the file to FULL STOP processing and no more validation hints are given).
What issues does this PR fix or reference?
If a file has a relative
# yaml-language-server: $schema=./...and that schema has a$ref: "./path-b.schema.yaml"(with a full$id: "https://example.com/my/path-b.yaml") which may refer to a$ref: "./path-c.schema.yaml"(with a full$id: "https://example.com/my/path-c.yaml") that may refer back to path-a, AJV can end up being confused and cause infinite recursion.Is it tested? How?
Multi-step recursion tested in vscode-yaml:
Details
So now you open up example.yaml and this particular case works well the first time. But if you comment out
- $ref: "./text.schema.yaml", check that example.yaml goes to invalid, then uncomment it, it would have stopped working, but with my change, it now continues to work with a logged: