Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

fix: show helpful error message when port is occupied #5146

Merged
merged 2 commits into from
Dec 13, 2022

Conversation

jeffsmale90
Copy link
Contributor

No description provided.

@jeffsmale90 jeffsmale90 changed the title Fix error where incorrect error is raised when the selected port is in use fix: show helpful error message when port is occupied Dec 12, 2022
const { message, stack} = err;
let {code} = err;
// todo: we may be able to remove this check once https://github.com/trufflesuite/ganache/issues/4020 is resolved
if (code === undefined && message && message.indexOf("listen EADDRINUSE") === 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be > 0? If it's supposed to be 0, then perhaps use string.startsWith?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be string.startsWith because the error message explicitly is listen EADDRINUSE: <reason> - I'll change to that.

Thanks!

@@ -108,7 +108,16 @@ async function startServer(options) {
try {
await server.listen(options.port, options.hostname);
} catch (err) {
process.send({ type: "start-error", data: {code: err.code, stack: err.stack, message: err.message} });
const { message, stack} = err;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const { message, stack} = err;
const { message, stack } = err;

@@ -108,7 +108,16 @@ async function startServer(options) {
try {
await server.listen(options.port, options.hostname);
} catch (err) {
process.send({ type: "start-error", data: {code: err.code, stack: err.stack, message: err.message} });
const { message, stack} = err;
let {code} = err;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let {code} = err;
let { code } = err;

@@ -19,6 +19,7 @@ process.on("unhandledRejection", err => {

process.on("uncaughtException", err => {
//console.log('uncaught exception:', err.stack || err)
// hilariously EADDRINUSE errors will get raised here
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// hilariously EADDRINUSE errors will get raised here
// hilariously, EADDRINUSE errors will get raised here

@@ -108,9 +108,16 @@ async function startServer(options) {
try {
await server.listen(options.port, options.hostname);
} catch (err) {
const { message, stack} = err;
let {code} = err;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let {code} = err;
let { code } = err;

@@ -108,9 +108,16 @@ async function startServer(options) {
try {
await server.listen(options.port, options.hostname);
} catch (err) {
const { message, stack} = err;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const { message, stack} = err;
const { message, stack } = err;

@jeffsmale90 jeffsmale90 merged commit c5bfe6a into develop Dec 13, 2022
@jeffsmale90
Copy link
Contributor Author

@davidmurdoch @cds-amal I've made those changes, and merged, just because I wanted to incorporate into the github actions branch.

If you have any more concerns, I'm happy to fix them up.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants