Browse Source

exit the process immediately upon Ctrl+C (#540)

During the deployment selection prompt, don't print out a stack
trace of the "Aborted" error to the user, just exit the process
directly.
master
Nathan Rajlich 8 years ago
committed by Guillermo Rauch
parent
commit
4f64762ffc
  1. 15
      bin/now-deploy.js
  2. 10
      lib/utils/prompt-options.js

15
bin/now-deploy.js

@ -348,7 +348,7 @@ async function sync({ token, config: { currentTeam, user } }) {
let meta let meta
await retry( await retry(
async bail => { async () => {
try { try {
meta = await readMetaData(path, { meta = await readMetaData(path, {
deploymentType, deploymentType,
@ -399,8 +399,13 @@ async function sync({ token, config: { currentTeam, user } }) {
] ]
]) ])
} catch (err) { } catch (err) {
console.error(err) if (err.code === 'USER_ABORT') {
return bail() if (debug) {
console.log(`> [debug] Got Ctrl+C, aborting`)
}
return exit(1)
}
throw err
} }
if (debug) { if (debug) {
@ -412,9 +417,9 @@ async function sync({ token, config: { currentTeam, user } }) {
// Invoke async-retry and try again with the explicit deployment type // Invoke async-retry and try again with the explicit deployment type
throw err throw err
} }
} else {
return stopDeployment(err)
} }
return stopDeployment(err)
} }
}, },
{ {

10
lib/utils/prompt-options.js

@ -1,7 +1,9 @@
// Packages // Packages
const chalk = require('chalk') const chalk = require('chalk')
module.exports = function(opts) { module.exports = promptOptions
function promptOptions(opts) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
opts.forEach(([, text], i) => { opts.forEach(([, text], i) => {
console.log(`${chalk.gray('>')} [${chalk.bold(i + 1)}] ${text}`) console.log(`${chalk.gray('>')} [${chalk.bold(i + 1)}] ${text}`)
@ -15,10 +17,12 @@ module.exports = function(opts) {
process.stdin.removeListener('data', ondata) process.stdin.removeListener('data', ondata)
} }
// Ctrl + C
if (s === '\u0003') { if (s === '\u0003') {
cleanup() cleanup()
reject(new Error('Aborted')) const err = new Error('Aborted')
return err.code = 'USER_ABORT'
return reject(err)
} }
const n = Number(s) const n = Number(s)

Loading…
Cancel
Save