Semi improve error output

This commit is contained in:
Lumeille 2024-03-10 16:54:39 +11:00
parent f083b02491
commit 2d4a6073a6
1 changed files with 20 additions and 2 deletions

View File

@ -1,5 +1,6 @@
import { readFileSync } from "fs"
import { z } from "zod"
import { exit } from "process"
import { ZodError, z } from "zod"
export const defaultInterval = 60
export const defaultNotifyInterval = 300
@ -47,4 +48,21 @@ const configSchema = z.object({
export type Config = z.infer<typeof configSchema>
export const config = configSchema.parse(JSON.parse(readFileSync("./config.json").toString()))
const loadConfig = () => {
try {
return configSchema.parse(JSON.parse(readFileSync("./config.json").toString()))
}
catch(e) {
const err = e as ZodError | SyntaxError
if (err instanceof ZodError) {
console.error(err.flatten())
}
else {
console.error(err.message)
}
exit(1)
}
}
export const config = loadConfig()