|
3 | 3 | /* eslint-disable no-console */
|
4 | 4 | 'use strict'
|
5 | 5 |
|
6 |
| -process.on('uncaughtException', (err) => { |
7 |
| - console.info(err) |
| 6 | +const semver = require('semver') |
| 7 | +const YargsPromise = require('yargs-promise') |
| 8 | +const updateNotifier = require('update-notifier') |
| 9 | +const debug = require('debug')('ipfs:cli') |
| 10 | +const parser = require('./parser') |
| 11 | +const commandAlias = require('./command-alias') |
| 12 | +const { print } = require('./utils') |
| 13 | +const pkg = require('../../package.json') |
8 | 14 |
|
9 |
| - throw err |
| 15 | +// Handle any uncaught error |
| 16 | +process.once('uncaughtException', (err, origin) => { |
| 17 | + if (origin === 'uncaughtException') { |
| 18 | + print(err.message) |
| 19 | + debug(err) |
| 20 | + } |
10 | 21 | })
|
11 |
| - |
12 |
| -process.on('unhandledRejection', (err) => { |
13 |
| - console.info(err) |
14 |
| - |
15 |
| - throw err |
| 22 | +process.once('unhandledRejection', (err) => { |
| 23 | + print(err.message) |
| 24 | + debug(err) |
16 | 25 | })
|
17 | 26 |
|
18 |
| -const semver = require('semver') |
19 |
| -const pkg = require('../../package.json') |
20 |
| - |
| 27 | +// Check for node version |
21 | 28 | if (!semver.satisfies(process.versions.node, pkg.engines.node)) {
|
22 | 29 | console.error(`Please update your Node.js version to ${pkg.engines.node}`)
|
23 | 30 | process.exit(1)
|
24 | 31 | }
|
25 | 32 |
|
26 |
| -const YargsPromise = require('yargs-promise') |
27 |
| -const updateNotifier = require('update-notifier') |
28 |
| -const onExit = require('async-exit-hook') |
29 |
| -const utils = require('./utils') |
30 |
| -const print = utils.print |
31 |
| -const debug = require('debug')('ipfs:cli') |
32 |
| -const parser = require('./parser') |
33 |
| -const commandAlias = require('./command-alias') |
34 |
| - |
| 33 | +// Check if an update is available and notify |
35 | 34 | const oneWeek = 1000 * 60 * 60 * 24 * 7
|
36 | 35 | updateNotifier({ pkg, updateCheckInterval: oneWeek }).notify()
|
37 | 36 |
|
|
50 | 49 | }
|
51 | 50 | })
|
52 | 51 | .catch(({ error, argv }) => {
|
| 52 | + console.log('TCL: error', error) |
| 53 | + |
53 | 54 | getIpfs = argv.getIpfs
|
54 |
| - if (error) { |
55 |
| - throw error |
| 55 | + if (error.message) { |
| 56 | + print(error.message) |
| 57 | + debug(error) |
| 58 | + } else { |
| 59 | + print('Unknown error, please re-run the command with DEBUG=ipfs:cli to see debug output') |
| 60 | + debug(error) |
| 61 | + } |
| 62 | + process.exit(1) |
| 63 | + }) |
| 64 | + .finally(() => { |
| 65 | + if (getIpfs && getIpfs.instance) { |
| 66 | + const cleanup = getIpfs.rest[0] |
| 67 | + return cleanup() |
56 | 68 | }
|
57 |
| - throw new Error('Unknown error, please re-run the command with DEBUG=ipfs:cli to see debug output') |
58 | 69 | })
|
59 |
| - |
60 |
| -onExit(cb => { |
61 |
| - // If an IPFS instance was used in the handler then clean it up here |
62 |
| - if (getIpfs && getIpfs.instance) { |
63 |
| - const cleanup = getIpfs.rest[0] |
64 |
| - |
65 |
| - return cleanup() |
66 |
| - .then(() => cb()) |
67 |
| - .catch(err => { |
68 |
| - print(err.message) |
69 |
| - debug(err) |
70 |
| - cb() |
71 |
| - }) |
72 |
| - } |
73 |
| - cb() |
74 |
| -}) |
75 |
| - |
76 |
| -onExit.unhandledRejectionHandler(err => { |
77 |
| - print(err.message) |
78 |
| - debug(err) |
79 |
| -}) |
0 commit comments