Skip to content

Commit

Permalink
fix: gracefully handle unhandled promises
Browse files Browse the repository at this point in the history
This prevents nuxt process exiting in dev mode on unhandled promises
  • Loading branch information
Pooya Parsa committed Jul 9, 2017
1 parent 4bf0a46 commit 85825d1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 11 additions & 0 deletions bin/nuxt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env node

// Node Source Map Support
// https://github.com/evanw/node-source-map-support
require('source-map-support').install()

const join = require('path').join

const defaultCommand = 'dev'
Expand All @@ -21,4 +25,11 @@ if (commands.has(cmd)) {

const bin = join(__dirname, 'nuxt-' + cmd)

// Console error unhandled promises
process.on('unhandledRejection', function (err) {
/* eslint-disable no-console */
console.error(err)
console.error('[nuxt] Unhandled promise rejection: ' + err)
})

require(bin)
5 changes: 0 additions & 5 deletions bin/nuxt-dev
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ const nuxtConfigFile = resolve(rootDir, argv['config-file'])
const nuxtConfig = loadNuxtConfig()
_.defaultsDeep(nuxtConfig, { watchers: { chokidar: { ignoreInitial: true } } })

// Fail if an error happened
process.on('unhandledRejection', function (err) {
throw err
})

// Start dev
let dev = startDev()

Expand Down

0 comments on commit 85825d1

Please sign in to comment.