Skip to content

Commit

Permalink
fix: improve error handling
Browse files Browse the repository at this point in the history
- Do not terminate the process in code, but throw errors
- Return rejected promises
  • Loading branch information
rdeltour committed Sep 28, 2017
1 parent f8237d7 commit 8591a08
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/checker/checker-nightmare.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ const winston = require('winston');
const PATH_TO_AXE = path.join(path.dirname(require.resolve('axe-core')), 'axe.min.js');
if (!fs.existsSync(PATH_TO_AXE)) {
winston.verbose(PATH_TO_AXE);
process.exit(1);
throw new Error('Can’t find aXe');
}

const PATH_TO_H5O = path.join(path.dirname(require.resolve('h5o')), 'dist/outliner.min.js');
if (!fs.existsSync(PATH_TO_H5O)) {
winston.verbose(PATH_TO_H5O);
process.exit(1);
throw new Error('Can’t find h5o');
}

const PATH_TO_ACE_AXE = path.join(__dirname, '../scripts/ace-axe.js');
if (!fs.existsSync(PATH_TO_ACE_AXE)) {
winston.verbose(PATH_TO_ACE_AXE);
process.exit(1);
throw new Error('Can’t find ace-axe script');
}

const PATH_TO_ACE_EXTRACTION = path.join(__dirname, '../scripts/ace-extraction.js');
if (!fs.existsSync(PATH_TO_ACE_EXTRACTION)) {
winston.verbose(PATH_TO_ACE_EXTRACTION);
process.exit(1);
throw new Error('Can’t find ace-extraction script');
}
// EMXIF

Expand Down
8 changes: 6 additions & 2 deletions src/cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

const ace = require('../core/ace.js');
const meow = require('meow');
const winston = require('winston');

const cli = meow(`
Usage
Expand Down Expand Up @@ -40,6 +41,9 @@ ace(cli.input[0], {
tmpdir: cli.flags.tempdir,
verbose: cli.flags.verbose,
silent: cli.flags.silent,
jobId: ''
jobId: '',
})
.catch(() => process.exit(1));
.catch((err) => {
winston.error(err.message);
process.exit(1);
});
2 changes: 1 addition & 1 deletion src/core/ace.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = function ace(epubPath, options) {
// Check that the EPUB exists
if (!fs.existsSync(epubPath)) {
winston.error(`Couldn’t find EPUB file '${epubPath}'`);
reject(jobId);
return reject(jobId);
}

// Process options
Expand Down

0 comments on commit 8591a08

Please sign in to comment.