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

Commit

Permalink
fix: show helpful error message when port is occupied (#5146)
Browse files Browse the repository at this point in the history
* Fix error where incorrect error is raised when the selected port is in use
* Styling fixes, and use string.prototype.startsWith
  • Loading branch information
jeffsmale90 authored Dec 13, 2022
1 parent 167c2a3 commit c5bfe6a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
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
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

0 comments on commit c5bfe6a

Please sign in to comment.