feat(server): improve error logging using banner

This commit is contained in:
Elian Doran
2026-03-28 11:23:44 +02:00
parent 82bac7b18f
commit 8ada23c9be
2 changed files with 8 additions and 15 deletions

View File

@@ -6,7 +6,7 @@ export default class ServerPlatformProvider implements PlatformProvider {
readonly isWindows = process.platform === "win32";
crash(message: string): void {
getLog().error(message);
getLog().banner(message);
process.exit(1);
}

View File

@@ -1,4 +1,4 @@
import { getMessagingProvider, utils } from "@triliumnext/core";
import { getMessagingProvider, getPlatform, utils } from "@triliumnext/core";
import type { Express } from "express";
import fs from "fs";
import http from "http";
@@ -155,20 +155,13 @@ function startHttpServer(app: Express) {
}
if (utils.isElectron()) {
import("electron").then(({ app, dialog }) => {
// Not all situations require showing an error dialog. When Trilium is already open,
// clicking the shortcut, the software icon, or the taskbar icon, or when creating a new window,
// should simply focus on the existing window or open a new one, without displaying an error message.
if ("code" in error && error.code === "EADDRINUSE" && (process.argv.includes("--new-window") || !app.requestSingleInstanceLock())) {
console.error(message);
} else {
dialog.showErrorBox("Error while initializing the server", message);
}
process.exit(1);
});
if ("code" in error && error.code === "EADDRINUSE" && (process.argv.includes("--new-window") || !app.requestSingleInstanceLock())) {
console.error(message);
} else {
getPlatform().crash(`Error while initializing the server: ${message}`);
}
} else {
console.error(message);
process.exit(1);
getPlatform().crash(message);
}
});