Skip to content

Commit 7104ad1

Browse files
Pruthvi ShettyPruthvi Shetty
authored andcommitted
config: log diagnostic warnings instead of silently swallowing errors in config recovery
Replace empty catch blocks in io.observe-recovery.ts with diagnostic logger.warn() calls so failures in config health tracking, clobbered snapshot persistence, and backup restoration are visible in logs. Fix misleading 'Config auto-restored from backup' warning that fired even when the copyFile restore actually failed — the message now reflects the actual outcome.
1 parent 4108901 commit 7104ad1

1 file changed

Lines changed: 34 additions & 8 deletions

File tree

src/config/io.observe-recovery.ts

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@ async function writeConfigHealthState(
215215
encoding: "utf-8",
216216
mode: 0o600,
217217
});
218-
} catch {}
218+
} catch (err) {
219+
deps.logger.warn(
220+
`Failed to write config health state: ${err instanceof Error ? err.message : String(err)}`,
221+
);
222+
}
219223
}
220224

221225
function writeConfigHealthStateSync(deps: ObserveRecoveryDeps, state: ConfigHealthState): void {
@@ -226,7 +230,11 @@ function writeConfigHealthStateSync(deps: ObserveRecoveryDeps, state: ConfigHeal
226230
encoding: "utf-8",
227231
mode: 0o600,
228232
});
229-
} catch {}
233+
} catch (err) {
234+
deps.logger.warn(
235+
`Failed to write config health state: ${err instanceof Error ? err.message : String(err)}`,
236+
);
237+
}
230238
}
231239

232240
function getConfigHealthEntry(state: ConfigHealthState, configPath: string): ConfigHealthEntry {
@@ -365,7 +373,10 @@ async function persistClobberedConfigSnapshot(params: {
365373
flag: "wx",
366374
});
367375
return targetPath;
368-
} catch {
376+
} catch (err) {
377+
params.deps.logger.warn(
378+
`Failed to persist clobbered config snapshot: ${err instanceof Error ? err.message : String(err)}`,
379+
);
369380
return null;
370381
}
371382
}
@@ -384,7 +395,10 @@ function persistClobberedConfigSnapshotSync(params: {
384395
flag: "wx",
385396
});
386397
return targetPath;
387-
} catch {
398+
} catch (err) {
399+
params.deps.logger.warn(
400+
`Failed to persist clobbered config snapshot: ${err instanceof Error ? err.message : String(err)}`,
401+
);
388402
return null;
389403
}
390404
}
@@ -457,10 +471,16 @@ export async function maybeRecoverSuspiciousConfigRead(params: {
457471
try {
458472
await params.deps.fs.promises.copyFile(backupPath, params.configPath);
459473
restoredFromBackup = true;
460-
} catch {}
474+
} catch (err) {
475+
params.deps.logger.warn(
476+
`Failed to restore config from backup: ${err instanceof Error ? err.message : String(err)}`,
477+
);
478+
}
461479

462480
params.deps.logger.warn(
463-
`Config auto-restored from backup: ${params.configPath} (${suspicious.join(", ")})`,
481+
restoredFromBackup
482+
? `Config auto-restored from backup: ${params.configPath} (${suspicious.join(", ")})`
483+
: `Config backup restore failed: ${params.configPath} (${suspicious.join(", ")})`,
464484
);
465485
await appendConfigAuditRecord({
466486
fs: params.deps.fs,
@@ -594,10 +614,16 @@ export function maybeRecoverSuspiciousConfigReadSync(params: {
594614
try {
595615
params.deps.fs.copyFileSync(backupPath, params.configPath);
596616
restoredFromBackup = true;
597-
} catch {}
617+
} catch (err) {
618+
params.deps.logger.warn(
619+
`Failed to restore config from backup: ${err instanceof Error ? err.message : String(err)}`,
620+
);
621+
}
598622

599623
params.deps.logger.warn(
600-
`Config auto-restored from backup: ${params.configPath} (${suspicious.join(", ")})`,
624+
restoredFromBackup
625+
? `Config auto-restored from backup: ${params.configPath} (${suspicious.join(", ")})`
626+
: `Config backup restore failed: ${params.configPath} (${suspicious.join(", ")})`,
601627
);
602628
appendConfigAuditRecordSync({
603629
fs: params.deps.fs,

0 commit comments

Comments
 (0)