From dcfdb67539bcf67d817fa2a75d1099e148fee26e Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sat, 11 Jan 2025 13:30:39 +0100 Subject: [PATCH] refactor(backend_log): improve handle 'file not found' handle errors more "user friendly" and actually let the user know, that either the file is not existing (yet), or that reading the log failed. --- src/routes/api/backend_log.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/routes/api/backend_log.ts b/src/routes/api/backend_log.ts index acb6d3271..a20e14ebd 100644 --- a/src/routes/api/backend_log.ts +++ b/src/routes/api/backend_log.ts @@ -14,10 +14,16 @@ async function getBackendLog() { const file = join(LOG_DIR, fileName); return await readFile(file, "utf8"); } catch (e) { - log.error((e instanceof Error) ? e : `Reading the backend log '${fileName}' failed with an unknown error.`); + const isErrorInstance = e instanceof Error; // most probably the log file does not exist yet - https://github.com/zadam/trilium/issues/1977 - return ""; + if (isErrorInstance && "code" in e && e.code === "ENOENT") { + log.error(e); + return `The backend log file '${fileName}' does not exist (yet).`; + } + + log.error(isErrorInstance ? e : `Reading the backend log '${fileName}' failed with an unknown error: '${e}'.`); + return `Reading the backend log '${fileName}' failed.`; } }