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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,9 @@ app.on('ready', async () => {
});

integrations.on("start-error", err => {
err.code = "CUSTOMERROR";
if (err.code === undefined) {
err.code = "CUSTOMERROR";
}
err.key = "workspace.server.chain";
err.value = err.message + "\n\n" + err.stack;
err.tab = "server";
Expand Down
9 changes: 8 additions & 1 deletion static/node/chain/chain.ethereum.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
// todo: we may be able to remove this check once https://github.com/trufflesuite/ganache/issues/4020 is resolved
if (code === undefined && message && message.startsWith("listen EADDRINUSE")) {
code = "EADDRINUSE";
}

process.send({
type: "start-error",
data: { code: err.code, stack: err.stack, message: err.message },
data: { code, stack, message },
});
return;
}
Expand Down
1 change: 1 addition & 0 deletions static/node/chain/chain.ethereum.v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

process.send({ type: "error", data: copyErrorFields(err) });
});

Expand Down
13 changes: 11 additions & 2 deletions static/node/chain/chain.filecoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async function stopServer() {
async function startServer(options) {
await stopServer();

let sanitizedOptions = Object.assign({}, options);
const sanitizedOptions = Object.assign({}, options);
if (sanitizedOptions.chain && sanitizedOptions.chain.mnemonic) {
delete sanitizedOptions.chain.mnemonic;
}
Expand Down Expand Up @@ -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;
// todo: we may be able to remove this check once https://github.com/trufflesuite/ganache/issues/4020 is resolved
if (code === undefined && message && message.startsWith("listen EADDRINUSE")) {
code = "EADDRINUSE";
}

process.send({ type: "start-error",
data: { code, stack, message },
});
return;
}

Expand Down