Skip to content

Commit

Permalink
Fix validate command not printing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
NikxDa committed Nov 29, 2024
1 parent 3fece22 commit 3aa449a
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/commands/validate.command.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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:');
Expand All @@ -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}`);
}
Expand Down

0 comments on commit 3aa449a

Please sign in to comment.