Skip to content

Commit 8591a08

Browse files
committed
fix: improve error handling
- Do not terminate the process in code, but throw errors - Return rejected promises
1 parent f8237d7 commit 8591a08

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/checker/checker-nightmare.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ const winston = require('winston');
1010
const PATH_TO_AXE = path.join(path.dirname(require.resolve('axe-core')), 'axe.min.js');
1111
if (!fs.existsSync(PATH_TO_AXE)) {
1212
winston.verbose(PATH_TO_AXE);
13-
process.exit(1);
13+
throw new Error('Can’t find aXe');
1414
}
1515

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

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

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

src/cli/cli.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
const ace = require('../core/ace.js');
66
const meow = require('meow');
7+
const winston = require('winston');
78

89
const cli = meow(`
910
Usage
@@ -40,6 +41,9 @@ ace(cli.input[0], {
4041
tmpdir: cli.flags.tempdir,
4142
verbose: cli.flags.verbose,
4243
silent: cli.flags.silent,
43-
jobId: ''
44+
jobId: '',
4445
})
45-
.catch(() => process.exit(1));
46+
.catch((err) => {
47+
winston.error(err.message);
48+
process.exit(1);
49+
});

src/core/ace.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = function ace(epubPath, options) {
2222
// Check that the EPUB exists
2323
if (!fs.existsSync(epubPath)) {
2424
winston.error(`Couldn’t find EPUB file '${epubPath}'`);
25-
reject(jobId);
25+
return reject(jobId);
2626
}
2727

2828
// Process options

0 commit comments

Comments
 (0)