Skip to content

Build your personal knowledge base with Trilium Notes

server,electron: Improve error logging

Elian Doran40651e985245
diff --git a/src/www.ts b/src/www.ts
index 3fc54e8176..847f93f8aa 100644
--- a/src/www.ts
+++ b/src/www.ts
@@ -126,6 +126,8 @@ function startHttpServer() {
}
httpServer.on('error', error => {
+ let message = error.message;
+
if (!listenOnTcp || ("syscall" in error && error.syscall !== 'listen')) {
throw error;
}
@@ -134,17 +136,28 @@ function startHttpServer() {
if ("code" in error) {
switch (error.code) {
case 'EACCES':
- console.error(`Port ${port} requires elevated privileges. It's recommended to use port above 1024.`);
- process.exit(1);
+ message = `Port ${port} requires elevated privileges. It's recommended to use port above 1024.`;
+ break;
case 'EADDRINUSE':
- console.error(`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.`);
- process.exit(1);
+ 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;
}
}
- throw error;
- }
- )
+ if (!message) {
+ message = "An unexpected error has occurred.";
+ }
+
+ if (utils.isElectron()) {
+ import("electron").then(({ dialog }) => {
+ dialog.showErrorBox("Error while initializing the server", message);
+ process.exit(1);
+ });
+ } else {
+ console.error(message);
+ process.exit(1);
+ }
+ });
httpServer.on('listening', () => {
if (listenOnTcp) {