Skip to content

Commit

Permalink
fix: do not hang on errors during HTML checking
Browse files Browse the repository at this point in the history
- Add a try/catch block in the code executed within
  Nightmare.js’s runtime, and dispatch the error to
  the callback
- Improve error reporting:
  - log verbose cause and throw a generic error
  - invite CLI users to re-run in verbose mode

Closes #39.
  • Loading branch information
rdeltour committed Oct 2, 2017
1 parent 4137b35 commit 54ebf5b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/checker/checker-nightmare.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ function checkSingle(spineItem, epub, nightmare) {
});
}
return results;
})
.catch((err) => {
winston.debug(`Error when running nightmare: ${JSON.stringify(err, null, 2)}`);
throw new Error('Failed to check HTML content');
});
}

Expand All @@ -93,4 +97,4 @@ module.exports.check = (epub) => {
return results;
})), Promise.resolve([]))
.then(results => nightmare.end(() => results));
}
};
1 change: 1 addition & 0 deletions src/cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,6 @@ ace(cli.input[0], {
})
.catch((err) => {
if (err) winston.error(err.message);
console.log(`Re-run Ace using the --verbose option to enable full debug logging.`)
process.exit(1);
});
3 changes: 2 additions & 1 deletion src/core/ace.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ module.exports = function ace(epubPath, options) {
resolve(jobId);
})
.catch((err) => {
winston.error(`Unexpected error: ${err}`);
winston.error(`Unexpected error: ${(err.message !== undefined) ? err.message : err}`);
if (err.stack !== undefined) winston.debug(err.stack);
reject(jobId);
});
});
Expand Down
8 changes: 6 additions & 2 deletions src/scripts/ace-axe.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,13 @@ daisy.ace.run = function(done) {

aceResult.axe = axeResult;

daisy.ace.createReport(aceResult);
try {
daisy.ace.createReport(aceResult);
done(null, aceResult);
} catch(e) {
done(e, null);
}

done(null, aceResult);
}
);
};
4 changes: 3 additions & 1 deletion tests/__tests__/__snapshots__/cli.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ exports[`test no input 2`] = `
"
`;
exports[`test unexisting input 1`] = `
exports[`test unexisting input 1`] = `"Re-run Ace using the --verbose option to enable full debug logging."`;
exports[`test unexisting input 2`] = `
"error: Couldn’t find EPUB file 'unexisting.epub'
"
`;
2 changes: 1 addition & 1 deletion tests/__tests__/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ test('test version --version', () => {
test('test unexisting input', () => {
const { stdout, stderr, status } = ace(['unexisting.epub']);
expect(status).toBe(1);
expect(stdout.trim()).toBe('');
expect(stdout.trim()).toMatchSnapshot();
expect(stderr).toMatchSnapshot();
});

Expand Down

0 comments on commit 54ebf5b

Please sign in to comment.