Skip to content

Fix 4357 - Properly catch and throw the error encountered while compiling bad schema #4723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,17 @@ should change the heading of the (upcoming) version to include a major version b
## @rjsf/validator-ajv8

- Updated `transformRJSFValidationErrors()` to include the `title` property of a field with error fixing #4504 with [PR](https://github.com/rjsf-team/react-jsonschema-form/pull/4700)
- Updated `AJVValidator` to handle the attempted compile of a bad schema, fixing [#4357](https://github.com/rjsf-team/react-jsonschema-form/issues/4357)

## Dev / docs / playground

- Added comprehensive documentation for dynamic UI schema feature with TypeScript examples ([#4706](https://github.com/rjsf-team/react-jsonschema-form/pull/4706))
- Updated array documentation to reference the new dynamic UI schema capabilities ([#4706](https://github.com/rjsf-team/react-jsonschema-form/pull/4706))
- Added comprehensive documentation for dynamic UI schema feature with TypeScript examples [#4706](https://github.com/rjsf-team/react-jsonschema-form/pull/4706)
- Updated array documentation to reference the new dynamic UI schema capabilities [#4706](https://github.com/rjsf-team/react-jsonschema-form/pull/4706)
- Updated nearly all of the libraries in the `package.json` files to the latest non-breaking versions
- Fixed the broken `Custom Array` sample
- Improved the `Any Of with Custom Field` sample so that it renders using the appropriate theme components
- Updated the `custom-widgets-fields.md` and `v6.x upgrade guide.md` to document the BREAKING CHANGE to the `FieldProps.onChange` behavior
- Updated the playground to properly output the `validationError` when running `Raw Validate`

# 6.0.0-beta.13

Expand Down
15 changes: 14 additions & 1 deletion packages/playground/src/components/RawValidatorTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@ export default function RawValidatorTest({ validator, schema, formData }: RawVal
if (rawValidation) {
displayErrors =
rawValidation.errors || rawValidation.validationError
? JSON.stringify(rawValidation, null, 2)
? JSON.stringify(
rawValidation,
(_, value: any) => {
if (value instanceof Error) {
return {
name: value.name,
message: value.message,
stack: value.stack,
};
}
return value;
},
2,
)
: 'No AJV errors encountered';
}
return (
Expand Down
6 changes: 3 additions & 3 deletions packages/validator-ajv8/src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ export default class AJV8Validator<T = any, S extends StrictRJSFSchema = RJSFSch
rawValidation<Result = any>(schema: S, formData?: T): RawValidationErrorsType<Result> {
let compilationError: Error | undefined = undefined;
let compiledValidator: ValidateFunction | undefined;
if (schema[ID_KEY]) {
compiledValidator = this.ajv.getSchema(schema[ID_KEY]);
}
try {
if (schema[ID_KEY]) {
compiledValidator = this.ajv.getSchema(schema[ID_KEY]);
}
if (compiledValidator === undefined) {
compiledValidator = this.ajv.compile(schema);
}
Expand Down