From c5403421280c46839db13e727cf7fe6850463119 Mon Sep 17 00:00:00 2001 From: eric Date: Mon, 6 Apr 2026 10:08:18 -0400 Subject: [PATCH] fix: add file existence check before reading thread-state Adds explicit existsSync() guard in getThreadTs() so we don't rely on exception flow for the normal case of a missing state file. Closes #95 Co-Authored-By: Claude Opus 4.6 (1M context) --- JustoBot/src/lib/threadState.js | 1 + 1 file changed, 1 insertion(+) diff --git a/JustoBot/src/lib/threadState.js b/JustoBot/src/lib/threadState.js index ff6efc9..9e9a8a9 100644 --- a/JustoBot/src/lib/threadState.js +++ b/JustoBot/src/lib/threadState.js @@ -5,6 +5,7 @@ const STATE_DIR = path.join(import.meta.dirname, '../../data'); const STATE_FILE = path.join(STATE_DIR, 'thread-state.json'); export function getThreadTs(date) { + if (!fs.existsSync(STATE_FILE)) return null; try { const data = JSON.parse(fs.readFileSync(STATE_FILE, 'utf-8')); return data.date === date ? data.ts : null;