Skip to content

Conversation

@mfori
Copy link
Member

@mfori mfori commented Nov 11, 2025

Solves https://github.com/apify/apify-core/issues/24045 - implements option to define custom error messages within the input schema based on the specification here: #556

Few notes to the implementation:

  1. It supports only property level validation keywords like type, minLength, pattern,.. but no schema/object level keywords (required, additionalProperties)

  2. It supports our custom validation keywords too (patternKey and patternValue)

  3. This allows to specify any validation keyword in any property. There is no check whether the property actually supports or moreover has defined the keyword. This makes the implementation much more simpler using one errorMessage definition and reusing it in all the properties.

  4. This would start working out-of-the box in the UI, but we use there custom function beautifyValidationMessage to modify the default error message for UI usecases and the custom message would just bubble through without any modification in most cases (there is regex check) - IMHO expected behavior, but mentioning it here to be sure.

@mfori mfori requested a review from Copilot November 11, 2025 15:15
@mfori mfori self-assigned this Nov 11, 2025
@mfori mfori added the t-console Issues with this label are in the ownership of the console team. label Nov 11, 2025
@github-actions github-actions bot added this to the 127th sprint - Console team milestone Nov 11, 2025
@github-actions github-actions bot added the tested Temporary label used only programatically for some analytics. label Nov 11, 2025
@mfori mfori requested review from fnesveda and valekjo November 11, 2025 15:20
@mfori mfori marked this pull request as ready for review November 11, 2025 15:20
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

This PR implements custom error messages for input schema validation, allowing developers to define field-specific error messages for validation keywords. This provides better user experience by enabling more contextual and user-friendly error messages.

Key Changes

  • Added errorMessage property definition to the JSON schema with support for all standard validation keywords (type, pattern, min/max constraints, etc.)
  • Implemented getCustomErrorMessage() function to retrieve custom messages from the schema based on validation paths
  • Integrated custom error message lookup into both AJV-based validation (parseAjvError) and pattern validation in utilities
  • Added comprehensive test coverage for all supported validation keywords and field types

Reviewed Changes

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

Show a summary per file
File Description
packages/json_schemas/schemas/input.schema.json Added errorMessage definition and referenced it in all property type definitions (string, array, object, integer, number, boolean, resource, any, and their sub-schema variants)
packages/input_schema/src/input_schema.ts Implemented getCustomErrorMessage() function and integrated it into parseAjvError() to prioritize custom messages over default ones
packages/input_schema/src/utilities.ts Integrated custom error message support for pattern validation (patternKey and patternValue) in various field types
test/input_schema.test.ts Added tests to validate schema accepts custom error messages and rejects unknown keywords
test/utilities.client.test.ts Added comprehensive test coverage for custom error messages across all validation keywords and field types

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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