Skip to content

Commit 4d57a2f

Browse files
refactor(db): readRawJson distinguishes ENOENT (silent) from real I/O faults
Code-review follow-up: the blanket catch swallowed permission/EISDIR/corrupt-read errors identically to the expected missing-file case. Branch on ENOENT (the forward-safe NULL-column / old-row case, kept silent to avoid per-row noise) and log any other read fault on a file that should exist. Also document in writeRawJson that a write failure means the diag blob for that row is unrecoverable (drawer degrades to empty, never errors).
1 parent 43fbb7b commit 4d57a2f

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

core/db.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ function rawJsonPath(run_id, result_id) {
3232
* (mirrors pipeline.js raw-write philosophy). Works for :memory: DBs too since
3333
* the path is independent of the DB backend.
3434
*
35+
* NOTE: if this write fails, the row's raw_json column is already NULL and no
36+
* file exists, so the full-diag blob for that result is unrecoverable — the
37+
* admin drawer degrades to an empty diag block (it never errors). The audit
38+
* log + results/runs/* JSON still capture the run, so this is an accepted
39+
* tradeoff, but a logged write failure here means lost diag for that one row.
40+
*
3541
* @param {number} run_id
3642
* @param {number|bigint} result_id
3743
* @param {string} json - the JSON.stringify(result) string
@@ -57,8 +63,14 @@ export function readRawJson(run_id, result_id) {
5763
if (run_id == null || result_id == null) return null;
5864
try {
5965
return readFileSync(rawJsonPath(run_id, result_id), 'utf8');
60-
} catch {
61-
// ENOENT or any read error → no blob available.
66+
} catch (e) {
67+
// A missing file is the expected forward-safe case (column was NULL and the
68+
// file was never written, or an old inline-blob row): stay silent — logging
69+
// per row would be noisy. Any OTHER fault (permissions, EISDIR, corrupt
70+
// read) is a real problem on a file that should exist — surface it.
71+
if (e && e.code !== 'ENOENT') {
72+
console.error('[db] raw_json file read failed:', e.message);
73+
}
6274
return null;
6375
}
6476
}

0 commit comments

Comments
 (0)