fix: throw a nice error if config does not exist
This commit is contained in:
parent
7a1433b830
commit
c9b9fe1eab
|
@ -2,6 +2,7 @@ import { Client, checkKey } from './client.js';
|
||||||
|
|
||||||
import fsp from 'node:fs/promises';
|
import fsp from 'node:fs/promises';
|
||||||
import Ajv from 'ajv';
|
import Ajv from 'ajv';
|
||||||
|
import { existsSync } from 'node:fs';
|
||||||
const ajv = new Ajv();
|
const ajv = new Ajv();
|
||||||
|
|
||||||
const config_validate = ajv.compile({
|
const config_validate = ajv.compile({
|
||||||
|
@ -30,6 +31,11 @@ export class Config {
|
||||||
|
|
||||||
static async load(): Promise<Config> {
|
static async load(): Promise<Config> {
|
||||||
const path = process.env.CONFIG_PATH ?? 'config.json';
|
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(
|
const raw = JSON.parse(
|
||||||
await fsp.readFile(path, { encoding: 'utf8' }),
|
await fsp.readFile(path, { encoding: 'utf8' }),
|
||||||
) as Config;
|
) as Config;
|
||||||
|
|
Loading…
Reference in New Issue