Skip to content

Reject an invalid schema every time it's validated - #134

Merged
jdesrosiers merged 1 commit into
hyperjump-io:mainfrom
MohitSAGAR11:fix-invalid-schema-revalidation
Oct 14, 2026
Merged

jdesrosiers merged 1 commit into
hyperjump-io:mainfrom
MohitSAGAR11:fix-invalid-schema-revalidation

Conversation

@MohitSAGAR11

Copy link
Copy Markdown
Contributor

Fixes #133

The meta-validation subscriber marks a schema as validated before checking it, and the mark stayed in place when the check failed. So only the first validate call threw InvalidSchemaError; later calls used the invalid schema, or crashed (TypeError: type.some is not a function for type: 5).

The mark still has to be set before checking, because a meta-schema validates against itself. I tried setting it only after a successful check, and Node aborted with infinite recursion. So it stays where it is, and it's now cleared if validation fails or anything in it throws (including loading or compiling the meta-schema). The schema is then validated again on the next call.

Tests

Added lib/meta-validation.spec.ts with two cases from the issue: validating an invalid schema twice, and validating after a failed compile. Both fail on main and pass with this change.

npm test (15,001 passed), lint and tsc --noEmit are all clean.

Not covered: if two validate calls for the same invalid schema run concurrently (e.g. in Promise.all), the second one still skips meta-validation while the first is in progress, so it can still hit the TypeError. That's the same as before this change. Fixing it would mean storing the in-progress validation and awaiting it instead of a boolean. Happy to do that here or in a follow-up if you want it, but I didn't want to widen the change without asking.

@jdesrosiers
jdesrosiers merged commit 478b2c7 into hyperjump-io:main Oct 14, 2026
2 checks passed
@MohitSAGAR11

MohitSAGAR11 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor Author

@jdesrosiers
Thanks for the quick review and merge!

Is there anything specific you'd like help with? Otherwise I'll keep doing what I did here: find bugs, open an issue with a repro, and send a fix once you're OK with it.

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.

An invalid schema is only rejected the first time it's validated

2 participants