diff --git a/package.json b/package.json index 9f64644baf..fc4ae8deb9 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,6 @@ "async-iterator-to-stream": "^1.1.0", "base32.js": "~0.1.0", "bignumber.js": "^9.0.0", - "async-exit-hook": "^2.0.1", "binary-querystring": "~0.1.2", "bl": "^3.0.0", "bs58": "^4.0.1", @@ -169,7 +168,6 @@ "readable-stream": "^3.4.0", "receptacle": "^1.3.2", "semver": "^6.2.0", - "signal-exit": "^3.0.2", "stream-to-pull-stream": "^1.7.3", "superstruct": "~0.6.0", "tar-stream": "^2.0.0", diff --git a/src/cli/bin.js b/src/cli/bin.js index 27ba86eb19..1e0668484b 100755 --- a/src/cli/bin.js +++ b/src/cli/bin.js @@ -3,35 +3,34 @@ /* eslint-disable no-console */ 'use strict' -process.on('uncaughtException', (err) => { - console.info(err) +const semver = require('semver') +const YargsPromise = require('yargs-promise') +const updateNotifier = require('update-notifier') +const debug = require('debug')('ipfs:cli') +const parser = require('./parser') +const commandAlias = require('./command-alias') +const { print } = require('./utils') +const pkg = require('../../package.json') - throw err +// Handle any uncaught error +process.once('uncaughtException', (err, origin) => { + if (origin === 'uncaughtException') { + print(err.message) + debug(err) + } }) - -process.on('unhandledRejection', (err) => { - console.info(err) - - throw err +process.once('unhandledRejection', (err) => { + print(err.message) + debug(err) }) -const semver = require('semver') -const pkg = require('../../package.json') - +// Check for node version if (!semver.satisfies(process.versions.node, pkg.engines.node)) { console.error(`Please update your Node.js version to ${pkg.engines.node}`) process.exit(1) } -const YargsPromise = require('yargs-promise') -const updateNotifier = require('update-notifier') -const onExit = require('async-exit-hook') -const utils = require('./utils') -const print = utils.print -const debug = require('debug')('ipfs:cli') -const parser = require('./parser') -const commandAlias = require('./command-alias') - +// Check if an update is available and notify const oneWeek = 1000 * 60 * 60 * 24 * 7 updateNotifier({ pkg, updateCheckInterval: oneWeek }).notify() @@ -50,30 +49,21 @@ cli } }) .catch(({ error, argv }) => { + console.log('TCL: error', error) + getIpfs = argv.getIpfs - if (error) { - throw error + if (error.message) { + print(error.message) + debug(error) + } else { + print('Unknown error, please re-run the command with DEBUG=ipfs:cli to see debug output') + debug(error) + } + process.exit(1) + }) + .finally(() => { + if (getIpfs && getIpfs.instance) { + const cleanup = getIpfs.rest[0] + return cleanup() } - throw new Error('Unknown error, please re-run the command with DEBUG=ipfs:cli to see debug output') }) - -onExit(cb => { - // If an IPFS instance was used in the handler then clean it up here - if (getIpfs && getIpfs.instance) { - const cleanup = getIpfs.rest[0] - - return cleanup() - .then(() => cb()) - .catch(err => { - print(err.message) - debug(err) - cb() - }) - } - cb() -}) - -onExit.unhandledRejectionHandler(err => { - print(err.message) - debug(err) -}) diff --git a/src/cli/commands/id.js b/src/cli/commands/id.js index 55b6bdad97..35de74baa1 100644 --- a/src/cli/commands/id.js +++ b/src/cli/commands/id.js @@ -16,7 +16,8 @@ module.exports = { argv.resolve((async () => { const ipfs = await argv.getIpfs() const id = await ipfs.id() - argv.print(JSON.stringify(id, '', 2)) + + return JSON.stringify(id, '', 2) })()) } } diff --git a/test/cli/config.js b/test/cli/config.js index 1687f2d7fb..f9d1c0458a 100644 --- a/test/cli/config.js +++ b/test/cli/config.js @@ -58,7 +58,7 @@ describe('config', () => runOnAndOff((thing) => { }) it('set a config key with invalid json', () => { - return ipfs.fail('config foo {"bar:0} --json') + return ipfs.fail('config foo {"bar:0"} --json') }) it('get a config key value', () => {