Skip to content

Commit

Permalink
Merge pull request #807 from macbre/improved-error-handling
Browse files Browse the repository at this point in the history
bin/phantomas.js should output Browser.visit() promise rejections to stderr
  • Loading branch information
macbre authored Oct 26, 2020
2 parents 853a293 + e3d7f73 commit 0ebdfd7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ jobs:
- name: Check that bin/phantomas.js works
run: ./bin/phantomas.js http://127.0.0.1:8888/ --pretty | grep "generator" -A4

- name: Check that bin/phantomas.js handles errors correctly
run: ./bin/phantomas.js http://127.0.0.1:1234/ 2>&1 | grep "net::ERR_CONNECTION_REFUSED at http://127.0.0.1:1234"
3 changes: 2 additions & 1 deletion bin/phantomas.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ if (!process.stdout.isTTY && options.colors !== true) {
phantomas(url, options)
.catch((err) => {
debug("Error: %s", err);
process.exit(1);
console.error("" + err);
process.exit(2);
})
.then(async (results) => {
debug("Calling a reporter...");
Expand Down
3 changes: 3 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ function phantomas(url, opts) {

resolve(results);
} catch (ex) {
debug("Exception caught: " + ex);
debug(ex);

// close the browser before leaving here, otherwise subsequent instances will have problems
await browser.close();
reject(ex);
Expand Down

0 comments on commit 0ebdfd7

Please sign in to comment.