Commit e280254d authored by Dan Abramov's avatar Dan Abramov Committed by GitHub
Browse files

Handle errors from port detector (#2182)

parent 46eeabca
Showing with 36 additions and 27 deletions
+36 -27
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
"react-scripts": "./bin/react-scripts.js" "react-scripts": "./bin/react-scripts.js"
}, },
"dependencies": { "dependencies": {
"@timer/detect-port": "1.1.2", "@timer/detect-port": "1.1.3",
"address": "1.0.1", "address": "1.0.1",
"autoprefixer": "7.1.0", "autoprefixer": "7.1.0",
"babel-core": "6.24.1", "babel-core": "6.24.1",
......
...@@ -140,33 +140,42 @@ function run(port) { ...@@ -140,33 +140,42 @@ function run(port) {
// We attempt to use the default port but if it is busy, we offer the user to // We attempt to use the default port but if it is busy, we offer the user to
// run on a different port. `detect()` Promise resolves to the next free port. // run on a different port. `detect()` Promise resolves to the next free port.
detect(DEFAULT_PORT, HOST).then(port => { detect(DEFAULT_PORT, HOST).then(
if (port === DEFAULT_PORT) { port => {
run(port); if (port === DEFAULT_PORT) {
return; run(port);
} return;
}
if (isInteractive) { if (isInteractive) {
clearConsole(); clearConsole();
const existingProcess = getProcessForPort(DEFAULT_PORT); const existingProcess = getProcessForPort(DEFAULT_PORT);
const question = { const question = {
type: 'confirm', type: 'confirm',
name: 'shouldChangePort', name: 'shouldChangePort',
message: chalk.yellow( message: chalk.yellow(
`Something is already running on port ${DEFAULT_PORT}.` + `Something is already running on port ${DEFAULT_PORT}.` +
`${existingProcess ? ` Probably:\n ${existingProcess}` : ''}` `${existingProcess ? ` Probably:\n ${existingProcess}` : ''}`
) + '\n\nWould you like to run the app on another port instead?', ) + '\n\nWould you like to run the app on another port instead?',
default: true, default: true,
}; };
inquirer.prompt(question).then(answer => { inquirer.prompt(question).then(answer => {
if (answer.shouldChangePort) { if (answer.shouldChangePort) {
run(port); run(port);
} }
}); });
} else { } else {
console.log(
chalk.red(`Something is already running on port ${DEFAULT_PORT}.`)
);
}
},
err => {
console.log( console.log(
chalk.red(`Something is already running on port ${DEFAULT_PORT}.`) chalk.red(`Could not find an open port at ${chalk.bold(HOST)}.`)
); );
console.log('Network error message: ' + err.message || err);
console.log();
} }
}); );
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment