11import { readdirSync } from "node:fs" ;
22import * as fs from "node:fs/promises" ;
33import * as path from "node:path" ;
4+ import { ZodError } from "zod" ;
45import { prettifyError } from "zod/mini" ;
56import { convertToZod , SchemaSchema } from "./shared" ;
67
@@ -10,15 +11,24 @@ async function processFile(filePath: string) {
1011 const yamlStr = await Bun . file ( normalizedFilePath ) . text ( ) ;
1112 const yamlContent = Bun . YAML . parse ( yamlStr ) ;
1213 const parsedSchema = SchemaSchema . safeParse ( yamlContent ) ;
13- console . log ( `Parsing ${ normalizedFilePath } ` ) ;
1414 if ( parsedSchema . error ) {
1515 console . error ( `Error while parsing ${ normalizedFilePath } ` ) ;
1616 console . error ( prettifyError ( parsedSchema . error ) ) ;
1717 throw parsedSchema . error ;
1818 }
19- const { zodSchema, refs : uniqueRefs } = convertToZod ( parsedSchema . data ) ;
19+ const { zodSchema, refs } = ( ( ) => {
20+ try {
21+ return convertToZod ( parsedSchema . data ) ;
22+ } catch ( e ) {
23+ if ( e instanceof ZodError ) {
24+ console . error ( `Error while converting ${ normalizedFilePath } ` ) ;
25+ console . error ( prettifyError ( e ) ) ;
26+ }
27+ throw e ;
28+ }
29+ } ) ( ) ;
2030
21- const refImports = uniqueRefs
31+ const refImports = refs
2232 . toSorted ( )
2333 . map ( ( refName ) => `import { ${ refName } } from "./${ refName } ";` as const )
2434 . join ( "\n" ) ;
0 commit comments