From c4ce83a93f36aacffb4136e57299d9109f3ba056 Mon Sep 17 00:00:00 2001 From: SOUMITRO-SAHA Date: Wed, 10 Jun 2026 20:10:23 +0530 Subject: [PATCH] fix: wrap getCurrentChatDir in try-catch to prevent startup crash The logger calls getCurrentChatDir() during early startup (triggered by fingerprint initialization), which tries to mkdir the chat directory. If the config directory hierarchy doesn't exist yet, this throws ENOENT and crashes the app since the call is in a fire-and-forget promise. Wrapping the call in try-catch (matching the existing pattern for getProjectRoot()) lets the logger gracefully skip file logging instead. --- cli/src/utils/logger.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/cli/src/utils/logger.ts b/cli/src/utils/logger.ts index 98a5410420..d5ee8aae5a 100644 --- a/cli/src/utils/logger.ts +++ b/cli/src/utils/logger.ts @@ -133,12 +133,19 @@ function sendAnalyticsAndLog( projectRoot = undefined } if (projectRoot) { - const logTarget = - IS_DEV - ? path.join(projectRoot, 'debug', 'cli.jsonl') - : path.join(getCurrentChatDir(), 'log.jsonl') + let logTarget: string | undefined + try { + logTarget = + IS_DEV + ? path.join(projectRoot, 'debug', 'cli.jsonl') + : path.join(getCurrentChatDir(), 'log.jsonl') + } catch { + // skip file logging if chat directory can't be created + } - setLogPath(logTarget) + if (logTarget) { + setLogPath(logTarget) + } } }