Skip to content

Commit

Permalink
Merge pull request #245 from WileyLabs/update-error-handling
Browse files Browse the repository at this point in the history
Improved handling of invalid YAML in domains.js
  • Loading branch information
alunwcom authored Oct 3, 2024
2 parents afebad6 + d18d6e6 commit 0a4687f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions commands/domains.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 !== '') {
Expand Down

0 comments on commit 0a4687f

Please sign in to comment.