Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved handling of invalid YAML in domains.js #245

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading