feat(input_schema): Custom error messages #567
+364
−28
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
It supports only property level validation keywords like
type,minLength,pattern,.. but no schema/object level keywords (required,additionalProperties)It supports our custom validation keywords too (
patternKeyandpatternValue)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
errorMessagedefinition and reusing it in all the properties.This would start working out-of-the box in the UI, but we use there custom function
beautifyValidationMessageto 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.