Skip to content

Commit 33c961b

Browse files
Fix 4357 - Properly catch and throw the error encountered while compiling bad schema
Fixed #4357 by properly catching the error caused by trying to compile a bad schema in the validator - Updated `validator.ts` to move the `this.ajv.getSchema()` call inside of the try/catch to deal with bad schemas properly - Updated the `RawValidatorTest.tsx` component to add a replacer function to the `JSON.stringify()` function to properly output the `validationError` - Updated `CHANGELOG.md` accordingly
1 parent 0748a0c commit 33c961b

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,17 @@ should change the heading of the (upcoming) version to include a major version b
7272
## @rjsf/validator-ajv8
7373

7474
- 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)
75+
- Updated `AJVValidator` to handle the attempted compile of a bad schema, fixing [#4357](https://github.com/rjsf-team/react-jsonschema-form/issues/4357)
7576

7677
## Dev / docs / playground
7778

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

8587
# 6.0.0-beta.13
8688

packages/playground/src/components/RawValidatorTest.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,20 @@ export default function RawValidatorTest({ validator, schema, formData }: RawVal
1616
if (rawValidation) {
1717
displayErrors =
1818
rawValidation.errors || rawValidation.validationError
19-
? JSON.stringify(rawValidation, null, 2)
19+
? JSON.stringify(
20+
rawValidation,
21+
(_, value: any) => {
22+
if (value instanceof Error) {
23+
return {
24+
name: value.name,
25+
message: value.message,
26+
stack: value.stack,
27+
};
28+
}
29+
return value;
30+
},
31+
2,
32+
)
2033
: 'No AJV errors encountered';
2134
}
2235
return (

packages/validator-ajv8/src/validator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ export default class AJV8Validator<T = any, S extends StrictRJSFSchema = RJSFSch
6262
rawValidation<Result = any>(schema: S, formData?: T): RawValidationErrorsType<Result> {
6363
let compilationError: Error | undefined = undefined;
6464
let compiledValidator: ValidateFunction | undefined;
65-
if (schema[ID_KEY]) {
66-
compiledValidator = this.ajv.getSchema(schema[ID_KEY]);
67-
}
6865
try {
66+
if (schema[ID_KEY]) {
67+
compiledValidator = this.ajv.getSchema(schema[ID_KEY]);
68+
}
6969
if (compiledValidator === undefined) {
7070
compiledValidator = this.ajv.compile(schema);
7171
}

0 commit comments

Comments
 (0)