From d18d6e6491251c3356c9e19946fb8143e3aef02b Mon Sep 17 00:00:00 2001 From: Alun 'Will' Williams Date: Thu, 3 Oct 2024 11:15:07 +0100 Subject: [PATCH] Improved handling of invalid YAML in domains.js --- commands/domains.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/commands/domains.js b/commands/domains.js index 6d43719..50f5d5c 100644 --- a/commands/domains.js +++ b/commands/domains.js @@ -2,7 +2,7 @@ * @copyright 2020 John Wiley & Sons, Inc. * @license MIT */ - +/* eslint no-console: "off" */ import * as fs from 'node:fs'; import * as path from 'node:path'; import chalk from 'chalk'; @@ -64,10 +64,17 @@ function confirmDomainAdditions(domains_to_add, account_name, account_id, argv) let description = ''; try { description = YAML.load(fs.readFileSync((redir_filepath))); + if (!description) { + throw new Error(`ERROR reading/parsing yaml file: ${redir_filepath}`); + } + if (!description.name || description.name !== domain) { + throw new Error(`ERROR domain mismatch in yaml file: ${redir_filepath}`); + } } catch (err) { - console.error(chalk.red(`${err.name}: ${err.reason}`)); - console.log(`Skipping ${domain} for now.`); + console.error(chalk.red(err.message)); + console.log(chalk.gray(`Skipping ${domain} for now.`)); confirmDomainAdditions(domains_to_add, account_name, account_id, argv); + return; } if (description !== '') {