Skip to content

Commit

Permalink
catch EADDRINUSE and ENOTFOUND on dev/view script
Browse files Browse the repository at this point in the history
Catches both these events when starting the server on develop and view 
scripts, displays error to user.
  • Loading branch information
AlyxMoon committed May 7, 2020
1 parent 478f981 commit 8cdbaae
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
18 changes: 17 additions & 1 deletion cli/develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,27 @@ const run = (args) => {
utils.log(`Serving auspice version ${version}${args.extend ? " with extensions" : ""}.`);
utils.log(handlerMsg);
utils.log("---------------------------------------------------\n\n");
}).on('error', (error) => {
if (error.code === 'EADDRINUSE') {
utils.error(`Port ${app.get('port')} is currently in use by another program.
You must either close that program or specify a different port by setting the shell variable "$PORT". Note that on MacOS / Linux ${chalk.yellow(`lsof -n -i :${app.get('port')} | grep LISTEN`)} should identify the process currently using the port.`);
}

if (error.code === 'ENOTFOUND') {
utils.error(`Host ${app.get('host')} is not a valid address. The server could not be started. If you did not provide a HOST environment variable when starting the app you may have HOST already set in your system. You can either change that variable, or override HOST when starting the app.
Example commands to fix:
${chalk.yellow('HOST="localhost" auspice develop')}
${chalk.yellow('HOST="localhost" npm run develop')}`);
}

utils.error(`Uncaught error in app.listen(). Code: ${error.code}`);
});


};

module.exports = {
addParser,
run,
run
};
21 changes: 14 additions & 7 deletions cli/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,21 @@ const run = (args) => {
utils.log(auspiceBuild.message);
utils.log(handlerMsg);
utils.log("---------------------------------------------------\n\n");
}).on('error', (err) => {
if (err.code === 'EADDRINUSE') {
utils.error(`Port ${app.get('port')} is currently in use by another program.
You must either close that program or specify a different port by setting the shell variable
"$PORT". Note that on MacOS / Linux, "lsof -n -i :${app.get('port')} | grep LISTEN" should
identify the process currently using the port.`);
}).on('error', (error) => {
if (error.code === 'EADDRINUSE') {
utils.error(`Port ${app.get('port')} is currently in use by another program.
You must either close that program or specify a different port by setting the shell variable "$PORT". Note that on MacOS / Linux ${chalk.yellow(`lsof -n -i :${app.get('port')} | grep LISTEN`)} should identify the process currently using the port.`);
}
utils.error(`Uncaught error in app.listen(). Code: ${err.code}`);

if (error.code === 'ENOTFOUND') {
utils.error(`Host ${app.get('host')} is not a valid address. The server could not be started. If you did not provide a HOST environment variable when starting the app you may have HOST already set in your system. You can either change that variable, or override HOST when starting the app.
Example commands to fix:
${chalk.yellow('HOST="localhost" auspice view')}
${chalk.yellow('HOST="localhost" npm run view')}`);
}

utils.error(`Uncaught error in app.listen(). Code: ${error.code}`);
});

};
Expand Down

0 comments on commit 8cdbaae

Please sign in to comment.