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 <noreply@anthropic.com>
This commit is contained in:
2026-04-01 04:27:55 +00:00
parent 67369b56be
commit f370b6d48d

View File

@@ -151,12 +151,14 @@ export class Simple_KeyValue_Store {
load() { load() {
const { data, storage_path } = this; const { data, storage_path } = this;
if (!fs.existsSync(storage_path)) { let file_contents;
return; 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')) { for (const line of file_contents.split('\n')) {
if (!line) continue; if (!line) continue;
const [key, value] = JSON.parse(line); const [key, value] = JSON.parse(line);