Semi improve error output
This commit is contained in:
parent
f083b02491
commit
2d4a6073a6
|
@ -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()
|
Loading…
Reference in New Issue