@@ -52,13 +52,15 @@ function validateObjectWithGbnfSchema<T extends GbnfJsonSchema>(object: any, sch
52
52
return true ;
53
53
}
54
54
55
- throw new Error ( `Expected one of ${ schema . type . join ( ", " ) } but got "${ typeof object } "` ) ;
55
+ throw new Error ( `Expected one type of [${
56
+ schema . type . map ( ( type ) => JSON . stringify ( type ) ) . join ( ", " )
57
+ } ] but got type "${ object === null ? null : typeof object } "`) ;
56
58
}
57
59
58
60
if ( validateImmutableType ( object , schema . type ) )
59
61
return true ;
60
62
61
- throw new Error ( `Expected "${ schema . type } " but got "${ typeof object } "` ) ;
63
+ throw new Error ( `Expected "${ schema . type } " but got "${ object === null ? "null" : typeof object } "` ) ;
62
64
}
63
65
64
66
function validateArray < T extends GbnfJsonArraySchema > ( object : any , schema : T ) : object is GbnfJsonSchemaToType < T > {
@@ -87,7 +89,7 @@ function validateObject<T extends GbnfJsonObjectSchema>(object: any, schema: T):
87
89
88
90
const missingKeys = schemaKeys . filter ( ( key ) => ! objectKeysSet . has ( key ) ) ;
89
91
if ( missingKeys . length > 0 )
90
- throw new TechnicalValidationError ( `Missing keys: ${ extraKeys . map ( ( key ) => JSON . stringify ( key ) ) . join ( ", " ) } ` ) ;
92
+ throw new TechnicalValidationError ( `Missing keys: ${ missingKeys . map ( ( key ) => JSON . stringify ( key ) ) . join ( ", " ) } ` ) ;
91
93
92
94
let res = true ;
93
95
for ( const key of schemaKeys )
@@ -117,9 +119,9 @@ function validateEnum<T extends GbnfJsonEnumSchema>(object: any, schema: T): obj
117
119
return true ;
118
120
}
119
121
120
- throw new TechnicalValidationError ( `Expected one of ${
122
+ throw new TechnicalValidationError ( `Expected one of [ ${
121
123
schema . enum . map ( ( item ) => JSON . stringify ( item ) ) . join ( ", " )
122
- } but got ${ JSON . stringify ( object ) } `) ;
124
+ } ] but got ${ JSON . stringify ( object ) } `) ;
123
125
}
124
126
125
127
function validateConst < T extends GbnfJsonConstSchema > ( object : any , schema : T ) : object is GbnfJsonSchemaToType < T > {
0 commit comments