From f370b6d48d806f5485cfcdd540751aab31678c9b Mon Sep 17 00:00:00 2001 From: mikael-lovqvists-claude-agent Date: Wed, 1 Apr 2026 04:27:55 +0000 Subject: [PATCH] Fix kv-store load to use try/catch instead of existsSync Replace check-then-read with read-and-catch-ENOENT. The existsSync pattern is redundant and slightly misleading; other errors still propagate. Co-Authored-By: Claude Sonnet 4.6 --- lib/kv-store.mjs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/kv-store.mjs b/lib/kv-store.mjs index 4d7a003..a2d096c 100644 --- a/lib/kv-store.mjs +++ b/lib/kv-store.mjs @@ -151,12 +151,14 @@ export class Simple_KeyValue_Store { load() { const { data, storage_path } = this; - if (!fs.existsSync(storage_path)) { - return; + let file_contents; + try { + file_contents = fs.readFileSync(storage_path, 'utf-8'); + } catch (e) { + if (e.code === 'ENOENT') { return; } + throw e; } - const file_contents = fs.readFileSync(storage_path, 'utf-8'); - for (const line of file_contents.split('\n')) { if (!line) continue; const [key, value] = JSON.parse(line);