From 3aa449a4787a2eff78bc75778d6955f9e61b2459 Mon Sep 17 00:00:00 2001 From: NikxDa Date: Sat, 30 Nov 2024 00:26:52 +0100 Subject: [PATCH] Fix validate command not printing errors --- src/commands/validate.command.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/commands/validate.command.ts b/src/commands/validate.command.ts index 8f6cede..f5cfbc7 100644 --- a/src/commands/validate.command.ts +++ b/src/commands/validate.command.ts @@ -1,3 +1,4 @@ +import toml from 'toml'; import { ArgumentsCamelCase, CommandModule } from 'yargs'; import { configSchema, getConfig, getConfigFile } from '../utils/config.js'; import fs from 'fs/promises'; @@ -29,12 +30,17 @@ const handleValidate = async (argv: ArgumentsCamelCase) => { process.exit(0); } else { - const config = await getConfig(argv); - logger.info('Validating configuration...'); try { - configSchema.parse(config); + logger.debug(`Reading configuration file...`); + const configContent = await fs.readFile(configPath, 'utf-8'); + + logger.debug(`Parsing configuration file...`); + const configData = toml.parse(configContent); + + logger.debug(`Parsing configuration schema...`); + configSchema.parse(configData); } catch (e) { if (e instanceof z.ZodError) { logger.error('Configuration file is invalid:'); @@ -43,6 +49,13 @@ const handleValidate = async (argv: ArgumentsCamelCase) => { `Path [${error.path.join('.')}]: ${error.message}` ); } + } else if (e instanceof Error && e.name === 'SyntaxError') { + const line = 'line' in e ? e.line : -1; + const column = 'column' in e ? e.column : -1; + + logger.error( + `Failed to parse configuration file: ${e.message} (line ${line}, column ${column})` + ); } else { logger.error(`An unexpected error occured: ${e}`); }