Skip to content

Commit

Permalink
fix(cli-38): catch all unhandled rejections
Browse files Browse the repository at this point in the history
Introduce a top-level listener that forces the process to terminate and
avoids having a broken process running in the background bound to a port
that needs to manually be identified and killed.
  • Loading branch information
varl committed Dec 7, 2021
1 parent 5f9c5bb commit 3f9f371
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cli/src/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const makeShell = require('../lib/shell')
const { validatePackage } = require('../lib/validatePackage')
const { handler: pack } = require('./pack.js')

process.on('unhandledRejection', err => {
throw err
})

const buildModes = ['development', 'production']

const getNodeEnv = () => {
Expand Down
4 changes: 4 additions & 0 deletions cli/src/commands/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ const { reporter } = require('@dhis2/cli-helpers-engine')
const fs = require('fs-extra')
const makePaths = require('../lib/paths')

process.on('unhandledRejection', err => {
throw err
})

const handler = async ({ cwd }) => {
const paths = makePaths(cwd)

Expand Down
4 changes: 4 additions & 0 deletions cli/src/commands/deduplicate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ const { reporter, chalk, exit } = require('@dhis2/cli-helpers-engine')
const makePaths = require('../lib/paths')
const { listDuplicates, fixDuplicates } = require('../lib/yarnDeduplicate')

process.on('unhandledRejection', err => {
throw err
})

const handler = async ({ cwd }) => {
const paths = makePaths(cwd)

Expand Down
4 changes: 4 additions & 0 deletions cli/src/commands/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const { createClient } = require('../lib/httpClient')
const parseConfig = require('../lib/parseConfig')
const makePaths = require('../lib/paths.js')

process.on('unhandledRejection', err => {
throw err
})

const dumpHttpError = (message, response) => {
if (!response) {
reporter.error(message)
Expand Down
4 changes: 4 additions & 0 deletions cli/src/commands/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ const { namespace, reporter } = require('@dhis2/cli-helpers-engine')
const i18n = require('../lib/i18n')
const makePaths = require('../lib/paths')

process.on('unhandledRejection', err => {
throw err
})

const generate = {
description:
'Generate JSON files compatible with i18next from po/pot files',
Expand Down
4 changes: 4 additions & 0 deletions cli/src/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ const fs = require('fs-extra')
const gitignore = require('parse-gitignore')
const makePaths = require('../lib/paths')

process.on('unhandledRejection', err => {
throw err
})

const ignorePatterns = ['node_modules', '.d2', 'src/locales', 'build']

const parseGitignore = gitignoreFile => {
Expand Down
4 changes: 4 additions & 0 deletions cli/src/commands/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ const makeBundle = require('../lib/makeBundle.js')
const parseConfig = require('../lib/parseConfig.js')
const makePaths = require('../lib/paths.js')

process.on('unhandledRejection', err => {
throw err
})

exports.command = 'pack [source]'

exports.describe = 'Create a .zip archive of a built application'
Expand Down
4 changes: 4 additions & 0 deletions cli/src/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const publishVersion = require('../lib/publishVersion.js')
const updateManifest = require('../lib/updateManifest.js')
const { handler: pack } = require('./pack.js')

process.on('unhandledRejection', err => {
throw err
})

const isValidServerVersion = v => !!/(\d+)\.(\d+)/.exec(v)

const requiredFields = new Set(['id', 'version', 'minDHIS2Version'])
Expand Down
4 changes: 4 additions & 0 deletions cli/src/commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const { compileServiceWorker } = require('../lib/pwa')
const makeShell = require('../lib/shell')
const { validatePackage } = require('../lib/validatePackage')

process.on('unhandledRejection', err => {
throw err
})

const defaultPort = 3000

const handler = async ({
Expand Down
4 changes: 4 additions & 0 deletions cli/src/commands/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ const exitOnCatch = require('../lib/exitOnCatch')
const loadEnvFiles = require('../lib/loadEnvFiles')
const makePaths = require('../lib/paths')

process.on('unhandledRejection', err => {
throw err
})

const getAppJestConfig = ({ jestConfigPath, paths }) => {
if (jestConfigPath) {
return require(path.resolve(paths.base, jestConfigPath))
Expand Down

0 comments on commit 3f9f371

Please sign in to comment.