From 8412038ffefbc685ab5740e2c8c256653cb1f619 Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Tue, 12 Nov 2019 22:32:11 -0800 Subject: [PATCH] feat: handle ENOTFOUND and ask users to report all other errors; closes #78 This PR will ask users to report unhandled rejections or uncaught exceptions to the project issue tracker. - added a test to check this is working - added dev dep [execa](https://npm.im/execa) for said test - added [buggin](https://npm.im/buggin) unexpected error output --- bin/good-first-issue.js | 13 +++++++++++-- package.json | 8 +++++--- tests/cli.spec.js | 13 +++++++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 tests/cli.spec.js diff --git a/bin/good-first-issue.js b/bin/good-first-issue.js index 201324d..2a389e8 100755 --- a/bin/good-first-issue.js +++ b/bin/good-first-issue.js @@ -1,5 +1,6 @@ #!/usr/bin/env node +require('buggin')(module) const cli = require('commander') const chalk = require('chalk') const opn = require('open') @@ -49,8 +50,16 @@ cli process.exitCode = 0 } } catch (err) { - console.error(err) - process.exitCode = 1 + if (err && typeof err === 'object') { + if (/ENOTFOUND/.test(err.message)) { + process.exitCode = 1 + return console.error(`${chalk.red('Problem!')} Unable to find api.github.com.\nPlease check your network connection and/or DNS configuration.`) + } + // add more cases here as they come up, and present user-friendly messages + } + + // let buggin handle it if it's anything else + throw err } }) .parse(process.argv) diff --git a/package.json b/package.json index 94802ad..be31ffb 100644 --- a/package.json +++ b/package.json @@ -20,9 +20,9 @@ ], "repository": { "type": "git", - "url": "https://github.com/bnb/good-first-issue.git" + "url": "https://github.com/cutenode/good-first-issue.git" }, - "homepage": "https://github.com/bnb/good-first-issue", + "homepage": "https://github.com/cutenode/good-first-issue", "keywords": [ "cli", "node-cli", @@ -43,7 +43,7 @@ "node": ">=8.0.0" }, "bugs": { - "url": "https://github.com/bnb/good-first-issue/issues", + "url": "https://github.com/cutenode/good-first-issue/issues", "email": "hello@bnb.im" }, "contributors": [ @@ -51,6 +51,7 @@ ], "dependencies": { "boxen": "^3.0.0", + "buggin": "^0.1.5", "chalk": "^2.4.1", "commander": "^2.19.0", "inquirer": "^6.2.0", @@ -58,6 +59,7 @@ "open": "^6.4.0" }, "devDependencies": { + "execa": "^3.3.0", "jest": "^23.6.0", "strip-ansi": "^5.0.0", "standard": "^14.0.0" diff --git a/tests/cli.spec.js b/tests/cli.spec.js new file mode 100644 index 0000000..1039dae --- /dev/null +++ b/tests/cli.spec.js @@ -0,0 +1,13 @@ +const execa = require('execa') + +const BIN_PATH = require.resolve('../bin/good-first-issue.js') + +test('should display link to report bug if project not found', async () => { + return expect( + execa(process.execPath, [ + BIN_PATH, + 'marvin-k-mooney/would-you-please-go-now' + ]) + ) + .resolves.toMatchObject({stderr: /The following unhandled rejection is likely a bug in good-first-issue/}) +});