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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user