Skip to content

Making getErrors synchronous#205

Open
Ahmedmhmud wants to merge 4 commits intohyperjump-io:mainfrom
Ahmedmhmud:making-getErrors-sync
Open

Making getErrors synchronous#205
Ahmedmhmud wants to merge 4 commits intohyperjump-io:mainfrom
Ahmedmhmud:making-getErrors-sync

Conversation

@Ahmedmhmud
Copy link
Copy Markdown

This PR removes async schema value lookups from the error formatting path and makes getErrors synchronous by resolving keyword values from the compiled AST to using it so it can be used in @hyperjump/json-schema as we need here (#204).

I replaced async schema reads with two AST resolver functions: getCompiledKeywordValue() for normal keyword lookups by schemaLocation, and getSiblingKeywordValue() for sibling keywords in the same parent node (like draft-04 min/max exclusivity and contains min/max contains). Then getErrors passes this resolver to handlers, so the whole error handling path is synchronous and no longer depends on await getSchema().

getErrors now passes an AST resolver to handlers, including recursive ones, and sibling-dependent keywords use sibling lookup from the same parent AST node. I also adjusted handlers for compiled value shapes (like regex, draft-04 tuples, and const/enum JSON strings), then updated types. All tests are still passing leaves us with the same behavior.

@jdesrosiers
Copy link
Copy Markdown
Collaborator

@srivastava-diya, please do the first review

Comment thread src/error-handlers/typeConstEnum.js Outdated
import { getSchema } from "@hyperjump/json-schema/experimental";
import * as Schema from "@hyperjump/browser";
import * as Instance from "@hyperjump/json-schema/instance/experimental";
import jsonStringify from "json-stringify-deterministic";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @Ahmedmhmud please remove the unused variables, as oxlint gives warning.

Comment thread src/index.d.ts Outdated
getSiblingKeywordValue: (
schemaLocation: string,
siblingKeywordUri: string
) => { keywordLocation: string; keywordValue: unknown } | undefined;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please run npm run lint command to know if there are any linting issues and fix them because upon raising a PR it causes build failure, you can also use npx oxlint src --fix to fix linting issues automatically if they are fixable.

Comment thread src/error-handlers/minimum.js Outdated
/** @type ErrorHandler */
const minimumErrorHandler = async (normalizedErrors, instance, localization) => {
const minimumErrorHandler = (normalizedErrors, instance, localization, resolver) => {
/** @type {{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here the JSDoc on if actually does nothing so i think we can either remove it or it can be moved to annotate resolver as a variable.

Comment thread src/error-handlers/contains.js Outdated
/** @type ErrorHandler */
const containsErrorHandler = async (normalizedErrors, instance, localization) => {
const containsErrorHandler = (normalizedErrors, instance, localization, resolver) => {
/** @type {{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSDoc @type above the if does nothing, it can be removed.

@Ahmedmhmud
Copy link
Copy Markdown
Author

Hi @jdesrosiers, @srivastava-diya
I did a clean up for the oxlint & JSDoc issues, is there anything else to do?

Comment thread src/index.d.ts Outdated
* readable messages.
*/
export type ErrorHandler = (normalizedErrors: InstanceOutput, instance: JsonNode, localization: Localization) => Promise<ErrorObject[]>;
export type ErrorHandler = (normalizedErrors: InstanceOutput, instance: JsonNode, localization: Localization, resolver?: ErrorResolver) => ErrorObject[];
Copy link
Copy Markdown
Contributor

@srivastava-diya srivastava-diya Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolver is now always required by handlers that use it, but it's still typed as optional. I think we make this required which removes the need for defensive checks entirely from the handlers.

Comment thread src/index.d.ts Outdated
* build errors in applicator error handlers.
*/
export const getErrors: (normalizedErrors: NormalizedOutput, instance: JsonNode, localization: Localization) => Promise<ErrorObject[]>;
export const getErrors: (normalizedErrors: NormalizedOutput, instance: JsonNode, localization: Localization, resolver?: ErrorResolver) => ErrorObject[];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same goes for this one, we can make the resolver required here.

@Ahmedmhmud Ahmedmhmud force-pushed the making-getErrors-sync branch from 0ece108 to d24ba98 Compare April 13, 2026 22:47
@Ahmedmhmud
Copy link
Copy Markdown
Author

I made resolver required in ErrorHandler and getErrors, then removed resolver checks from all handlers that use it.

@srivastava-diya
Copy link
Copy Markdown
Contributor

hey @jdesrosiers all my comments have been addressed, LGTM from my side.

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.

3 participants