fix: throw a nice error if config does not exist

This commit is contained in:
b1ek 2024-05-11 21:37:27 +10:00
parent 7a1433b830
commit c9b9fe1eab
Signed by: blek
GPG Key ID: 14546221E3595D0C
1 changed files with 6 additions and 0 deletions

View File

@ -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<Config> {
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;