From c9b9fe1eaba1257637fbd0e828f4c255bf050f01 Mon Sep 17 00:00:00 2001 From: b1ek Date: Sat, 11 May 2024 21:37:27 +1000 Subject: [PATCH] fix: throw a nice error if config does not exist --- src/config.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/config.ts b/src/config.ts index eaf2ab0..34905bd 100644 --- a/src/config.ts +++ b/src/config.ts @@ -2,6 +2,7 @@ import { Client, checkKey } from './client.js'; import fsp from 'node:fs/promises'; import Ajv from 'ajv'; +import { existsSync } from 'node:fs'; const ajv = new Ajv(); const config_validate = ajv.compile({ @@ -30,6 +31,11 @@ export class Config { static async load(): Promise { const path = process.env.CONFIG_PATH ?? 'config.json'; + + if (!existsSync(path)) { + throw new Error(`The config file ${path} does not exist`); + } + const raw = JSON.parse( await fsp.readFile(path, { encoding: 'utf8' }), ) as Config;