Skip to content

Commit

Permalink
Print pretty zod errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Protonull committed Aug 12, 2023
1 parent a8de923 commit bde0404
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion server/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Mutex } from 'async-mutex'
import * as errors from './deps/errors'
import * as json from './deps/json'
import * as z from 'zod'
import { fromZodError } from 'zod-validation-error'

export const DATA_FOLDER = process.env['MAPSYNC_DATA_DIR'] ?? './mapsync'
try {
Expand Down Expand Up @@ -40,7 +41,14 @@ function parseConfigFile<T>(
node_fs.writeFileSync(file, JSON.stringify(defaultContent, null, 2), 'utf8')
return defaultContent
}
return parser(json.parse(fileContents))
try {
return parser(json.parse(fileContents))
} catch (e) {
if (e instanceof z.ZodError) {
throw 'Could not parse ' + file + ': ' + fromZodError(e)
}
throw e
}
}

/**
Expand Down

0 comments on commit bde0404

Please sign in to comment.