Skip to content

Commit

Permalink
feat: handle ENOTFOUND and ask users to report all other errors; closes
Browse files Browse the repository at this point in the history
cutenode#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
  • Loading branch information
boneskull committed Dec 18, 2019
1 parent f708d61 commit fe02cec
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
13 changes: 11 additions & 2 deletions bin/good-first-issue.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node

require('buggin')(module)
const cli = require('commander')
const chalk = require('chalk')
const opn = require('open')
Expand Down Expand Up @@ -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)
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -43,21 +43,23 @@
"node": ">=8.0.0"
},
"bugs": {
"url": "https://github.com/bnb/good-first-issue/issues",
"url": "https://github.com/cutenode/good-first-issue/issues",
"email": "[email protected]"
},
"contributors": [
"Dhruv Jain <[email protected]> (https://maddhruv.github.io)"
],
"dependencies": {
"boxen": "^3.0.0",
"buggin": "^0.1.6",
"chalk": "^2.4.1",
"commander": "^2.19.0",
"inquirer": "^6.2.0",
"libgfi": "^1.0.2",
"open": "^6.4.0"
},
"devDependencies": {
"execa": "^3.3.0",
"jest": "^23.6.0",
"strip-ansi": "^5.0.0",
"standard": "^14.0.0"
Expand Down
13 changes: 13 additions & 0 deletions tests/cli.spec.js
Original file line number Diff line number Diff line change
@@ -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/})
});

0 comments on commit fe02cec

Please sign in to comment.