server: Improve error handling for invalid host

This commit is contained in:
Elian Doran 2024-08-31 23:38:30 +03:00
parent 40651e9852
commit 27f513e2a3
No known key found for this signature in database

View File

@ -126,11 +126,7 @@ function startHttpServer() {
}
httpServer.on('error', error => {
let message = error.message;
if (!listenOnTcp || ("syscall" in error && error.syscall !== 'listen')) {
throw error;
}
let message = error.stack || "An unexpected error has occurred.";
// handle specific listen errors with friendly messages
if ("code" in error) {
@ -141,13 +137,12 @@ function startHttpServer() {
case 'EADDRINUSE':
message = `Port ${port} is already in use. Most likely, another Trilium process is already running. You might try to find it, kill it, and try again.`;
break;
case 'EADDRNOTAVAIL':
message = `Unable to start the server on host '${host}'. Make sure the host (defined in 'config.ini' or via the 'TRILIUM_HOST' environment variable) is an IP address that can be listened on.`;
break;
}
}
if (!message) {
message = "An unexpected error has occurred.";
}
if (utils.isElectron()) {
import("electron").then(({ dialog }) => {
dialog.showErrorBox("Error while initializing the server", message);