Skip to content

Conversation

@mfori
Copy link
Member

@mfori mfori commented Feb 12, 2026

When an invalid editor value (e.g., "fileUpload" instead of "fileupload") was used on an array field, the error message only showed a single editor from the first oneOf branch instead of all valid options. Now the error lists all valid array editors when the value is completely outside the allowed set.

Reported here: https://apify.slack.com/archives/C0L33UM7Z/p1770826695378579

mfori and others added 2 commits February 12, 2026 11:16
…rray property

When an invalid editor value (e.g., "fileUpload" instead of "fileupload") was
used on an array field, the error message only showed a single editor from the
first oneOf branch instead of all valid options. Now the error lists all valid
array editors when the value is completely outside the allowed set.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Verifies that invalid editor values on nested (sub-schema) array
properties show all valid editors, not just a subset from a oneOf branch.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mfori mfori requested a review from Copilot February 12, 2026 10:35
@mfori mfori self-assigned this Feb 12, 2026
@mfori mfori added adhoc Ad-hoc unplanned task added during the sprint. t-console Issues with this label are in the ownership of the console team. labels Feb 12, 2026
@github-actions github-actions bot added this to the 134th sprint - Console team milestone Feb 12, 2026
@github-actions github-actions bot added the tested Temporary label used only programatically for some analytics. label Feb 12, 2026
@mfori mfori requested review from stetizu1 and valekjo February 12, 2026 10:37
Copy link

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

Improves human-readable AJV validation errors for input_schema by ensuring invalid editor values on array fields report the complete set of valid editors (instead of a misleading subset from a oneOf/anyOf branch), and updates/adds regression tests for this behavior.

Changes:

  • Add logic to select a more relevant AJV error and enhance enum errors from oneOf/anyOf branches to show top-level allowed values when the provided value is outside the allowed set.
  • Update existing array-editor validation tests to expect the full allowed editor list.
  • Add new tests covering invalid editor values on array properties (including nested/sub-schema arrays).

Reviewed changes

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

File Description
packages/input_schema/src/input_schema.ts Adds selectBestError and enhances enum error reporting to prefer full allowed editor lists when appropriate.
test/input_schema.test.ts Updates expected error messages and adds coverage for invalid array editor values (top-level and nested).

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

Comment on lines +159 to +181
function selectBestError(errors: ErrorObject[]): ErrorObject {
const branchPattern = /\/(oneOf|anyOf)\/\d+\//;
const nonBranchErrors = errors.filter(
(e) => !branchPattern.test(e.schemaPath) && e.keyword !== 'oneOf' && e.keyword !== 'anyOf',
);
return nonBranchErrors[0] ?? errors[0];
}

/**
* Validates a given object against the schema and throws a human-readable error.
*/
const validateAgainstSchemaOrThrow = (validator: Ajv, obj: Record<string, unknown>, inputSchema: Schema, rootName: string) => {
if (validator.validate(inputSchema, obj)) return;

const errorMessage = parseAjvError(validator.errors![0], rootName)?.message;
let bestError = selectBestError(validator.errors!);

/*
When the best AJV error comes from a oneOf/anyOf branch (showing only a subset of valid values),
and the schema has a broader top-level enum for the same property, and the input value is not in
that enum at all, the error is enhanced to show all valid values instead of just the branch subset.
*/
const branchPattern = /\/(oneOf|anyOf)\/\d+\//;
if (bestError.keyword === 'enum' && branchPattern.test(bestError.schemaPath)) {
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

branchPattern is declared both in selectBestError and again in validateAgainstSchemaOrThrow. Consider extracting it to a single module-level constant (or reusing the one from selectBestError) to avoid future divergence if the pattern needs to change.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-console Issues with this label are in the ownership of the console team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant