@@ -52,13 +52,15 @@ function validateObjectWithGbnfSchema<T extends GbnfJsonSchema>(object: any, sch
5252 return true ;
5353 }
5454
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 } "`) ;
5658 }
5759
5860 if ( validateImmutableType ( object , schema . type ) )
5961 return true ;
6062
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 } "` ) ;
6264}
6365
6466function 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):
8789
8890 const missingKeys = schemaKeys . filter ( ( key ) => ! objectKeysSet . has ( key ) ) ;
8991 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 ( ", " ) } ` ) ;
9193
9294 let res = true ;
9395 for ( const key of schemaKeys )
@@ -117,9 +119,9 @@ function validateEnum<T extends GbnfJsonEnumSchema>(object: any, schema: T): obj
117119 return true ;
118120 }
119121
120- throw new TechnicalValidationError ( `Expected one of ${
122+ throw new TechnicalValidationError ( `Expected one of [ ${
121123 schema . enum . map ( ( item ) => JSON . stringify ( item ) ) . join ( ", " )
122- } but got ${ JSON . stringify ( object ) } `) ;
124+ } ] but got ${ JSON . stringify ( object ) } `) ;
123125}
124126
125127function validateConst < T extends GbnfJsonConstSchema > ( object : any , schema : T ) : object is GbnfJsonSchemaToType < T > {
0 commit comments