Skip to content

fix(core): stringifyValidationFakilureto consider array[] path.#528

Merged
samchon merged 1 commit intomainfrom
fix/stringifyValidationFailure
Feb 11, 2026
Merged

fix(core): stringifyValidationFakilureto consider array[] path.#528
samchon merged 1 commit intomainfrom
fix/stringifyValidationFailure

Conversation

@samchon
Copy link
Member

@samchon samchon commented Feb 11, 2026

This pull request improves the clarity and completeness of validation failure stringification in the JsonUtil utility, especially for arrays and objects with missing elements or properties. It also standardizes function naming and enhances test coverage. The most important changes are grouped below.

Enhancements to Validation Failure Stringification:

  • Improved the stringifyValidationFailure function in JsonUtil to better display missing array elements and object properties, including showing undefined placeholders and error comments for missing values. This includes handling missing array element errors and undefined object entries with associated validation errors. [1] [2] [3] [4] [5] [6]
  • Added the getMissingArrayElementErrors helper to detect and annotate missing array elements with validation errors.
  • Enhanced the extractDirectChildKey function to correctly support both dot notation and bracket notation for object property paths, improving detection of missing properties.

Code Consistency and Refactoring:

  • Renamed stringifyValidateFailure to stringifyValidationFailure throughout the codebase for clarity and consistency, including all usages and exports. [1] [2] [3] [4] [5] [6]

Test Updates:

  • Updated tests to use the new stringifyValidationFailure function name, ensuring correctness and coverage for the improved stringification logic. [1] [2]

@samchon samchon self-assigned this Feb 11, 2026
Copilot AI review requested due to automatic review settings February 11, 2026 18:14
@samchon samchon added this to WrtnLabs Feb 11, 2026
@samchon samchon added the enhancement New feature or request label Feb 11, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 11, 2026

Open in StackBlitz

@agentica/benchmark

npm i https://pkg.pr.new/wrtnlabs/agentica/@agentica/benchmark@528

@agentica/chat

npm i https://pkg.pr.new/wrtnlabs/agentica/@agentica/chat@528

agentica

npm i https://pkg.pr.new/wrtnlabs/agentica@528

@agentica/core

npm i https://pkg.pr.new/wrtnlabs/agentica/@agentica/core@528

create-agentica

npm i https://pkg.pr.new/wrtnlabs/agentica/create-agentica@528

@agentica/rpc

npm i https://pkg.pr.new/wrtnlabs/agentica/@agentica/rpc@528

@agentica/vector-selector

npm i https://pkg.pr.new/wrtnlabs/agentica/@agentica/vector-selector@528

commit: d1d7bc6

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors and extends JsonUtil’s validation-failure stringification to better represent missing/undefined values (especially around arrays and object properties) and standardizes the exported method name to stringifyValidationFailure.

Changes:

  • Renames JsonUtil.stringifyValidateFailure to JsonUtil.stringifyValidationFailure and updates call sites.
  • Adds handling for wildcard array-element error paths (path[]) and includes undefined/missing object keys when errors exist.
  • Updates feature tests to use the renamed function.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
packages/core/src/utils/JsonUtil.ts Renames the stringify API and adds new formatting logic for missing array elements and missing/undefined object properties (plus improved path parsing).
packages/core/src/orchestrate/call.ts Updates validation error rendering to use the renamed JsonUtil.stringifyValidationFailure.
test/src/features/test_validation_error_stringify.ts Updates the test to call the renamed stringify function.
test/src/features/test_json_stringify_with_validation_failure.ts Updates the test to call the renamed stringify function.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +352 to +358
* - ExtractDirectChildKey("$input", "$input.email") => "email"
* - ExtractDirectChildKey("$input", "$input.user.email") => null (grandchild)
* - ExtractDirectChildKey("$input.user", "$input.user.email") => "email"
* - ExtractDirectChildKey("$input", "$input[0]") => null (array index, not object
* property)
* - ExtractDirectChildKey("$input", "$input["foo-bar"]") => "foo-bar"
* - ExtractDirectChildKey("$input", "$input["foo"]["bar"]") => null (grandchild)
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

JSDoc examples here have a few issues: the function name is shown as ExtractDirectChildKey (different casing than the actual extractDirectChildKey), and the bracket-notation examples include nested double quotes that are hard to read ("$input["foo-bar"]"). Consider fixing the casing and escaping/rewriting the examples for clarity (e.g., using single quotes around the whole path).

Suggested change
* - ExtractDirectChildKey("$input", "$input.email") => "email"
* - ExtractDirectChildKey("$input", "$input.user.email") => null (grandchild)
* - ExtractDirectChildKey("$input.user", "$input.user.email") => "email"
* - ExtractDirectChildKey("$input", "$input[0]") => null (array index, not object
* property)
* - ExtractDirectChildKey("$input", "$input["foo-bar"]") => "foo-bar"
* - ExtractDirectChildKey("$input", "$input["foo"]["bar"]") => null (grandchild)
* - extractDirectChildKey('$input', '$input.email') => "email"
* - extractDirectChildKey('$input', '$input.user.email') => null (grandchild)
* - extractDirectChildKey('$input.user', '$input.user.email') => "email"
* - extractDirectChildKey('$input', '$input[0]') => null (array index, not object
* property)
* - extractDirectChildKey('$input', '$input["foo-bar"]') => "foo-bar"
* - extractDirectChildKey('$input', '$input["foo"]["bar"]') => null (grandchild)

Copilot uses AI. Check for mistakes.
],
};
const str: string = JsonUtil.stringifyValidateFailure(failure);
const str: string = JsonUtil.stringifyValidationFailure(failure);
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

PR description mentions “enhances test coverage” for the new array/object missing-value stringification behavior, but the test changes in this PR appear to be only the function rename. If the intent is to cover the new path[] and bracket-notation handling, additional assertions/cases should be added here (or in new tests).

Copilot uses AI. Check for mistakes.
const propPath = Escaper.variable(key)
? `${path}.${key}`
: `${path}[${JSON.stringify(key)}]`;
return errors.some(e => e.path.startsWith(propPath));
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

In undefinedKeysWithErrors, e.path.startsWith(propPath) can match sibling keys (e.g. $input.a will also match $input.ab...), causing unrelated undefined properties to be rendered. Consider matching either the exact path or only descendant paths with a delimiter (e.g. propPath + "." or propPath + "[").

Suggested change
return errors.some(e => e.path.startsWith(propPath));
return errors.some((e) =>
e.path === propPath ||
e.path.startsWith(propPath + ".") ||
e.path.startsWith(propPath + "["),
);

Copilot uses AI. Check for mistakes.
Comment on lines +127 to +135
// Add missing element placeholders at the end for each [] error
if (hasMissingElements) {
const innerIndent = " ".repeat(tab + 1);
missingElementErrors.forEach((e, idx) => {
const errComment = ` // ❌ ${JSON.stringify([{ path: e.path, expected: e.expected, description: e.description }])}`;
const comma = idx < missingElementErrors.length - 1 ? "," : "";
lines.push(`${innerIndent}undefined${comma}${errComment}`);
});
}
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

The missing-array-element placeholder logic renders one undefined line per error at ${path}[]. If multiple validation errors share the same wildcard path (multiple expectations), this will look like multiple missing elements even though the count is unknown. Consider aggregating all ${path}[] errors into a single placeholder/comment, or otherwise avoid implying a specific number of missing elements.

Copilot uses AI. Check for mistakes.
export const JsonUtil = {
parse,
stringifyValidateFailure,
stringifyValidationFailure,
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

stringifyValidateFailure was renamed/removed from the JsonUtil surface. If external consumers import this util directly (even if not via utils/index.ts), this is a breaking change. Consider keeping a deprecated alias (stringifyValidateFailure: stringifyValidationFailure) for at least one release to preserve backwards compatibility.

Suggested change
stringifyValidationFailure,
stringifyValidationFailure,
// TODO [deprecated]: Remove in a future major version. Kept for backwards compatibility.
stringifyValidateFailure: stringifyValidationFailure,

Copilot uses AI. Check for mistakes.
@samchon samchon merged commit 8c14c25 into main Feb 11, 2026
19 checks passed
@samchon samchon deleted the fix/stringifyValidationFailure branch February 11, 2026 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants