Skip to content

Commit c7a8388

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 e6e3c99 commit c7a8388

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
@@ -65,12 +65,14 @@ should change the heading of the (upcoming) version to include a major version b
6565
## @rjsf/validator-ajv8
6666

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

6970
## Dev / docs / playground
7071

71-
- Added comprehensive documentation for dynamic UI schema feature with TypeScript examples ([#4706](https://github.com/rjsf-team/react-jsonschema-form/pull/4706))
72-
- Updated array documentation to reference the new dynamic UI schema capabilities ([#4706](https://github.com/rjsf-team/react-jsonschema-form/pull/4706))
72+
- Added comprehensive documentation for dynamic UI schema feature with TypeScript examples [#4706](https://github.com/rjsf-team/react-jsonschema-form/pull/4706)
73+
- Updated array documentation to reference the new dynamic UI schema capabilities [#4706](https://github.com/rjsf-team/react-jsonschema-form/pull/4706)
7374
- Updated nearly all of the libraries in the `package.json` files to the latest non-breaking versions
75+
- Updated the playground to properly output the `validationError` when running `Raw Validate`
7476

7577
# 6.0.0-beta.13
7678

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)