fix: stop logging settings.json contents from the git-fetch tick, and log an unreadable file once (release review)

The settings readers for git fetch and keep-warm no longer repeat V8's JSON.parse message, which
quotes the text around the fault and could print voiceSettings.apiKey. The 15 s scheduler tick now
logs an unreadable settings.json once, and again only after a successful read in between. Stale
comments that said settings.json is rewritten in place now say writes are atomic.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Codeman maintainer committed 2026-10-27 02:53:08 +01:00
1 parent 0f1fca6ea0
commit da740d4b00
4 files changed
+80 -14

No files matched your search

+19 -5
View File
@@ -1171,16 +1171,17 @@ export async function readKeepWarmSettingsOrThrow(): Promise<KeepWarmSettings> {
if ((err as NodeJS.ErrnoException).code === 'ENOENT') return keepWarmSettingsFrom({});
throw err;
}
return keepWarmSettingsFrom(JSON.parse(text) as Record<string, unknown>);
return keepWarmSettingsFrom(parseSettingsText(text));
}
/**
* The Git fetch interval's app-wide default (`gitFetchEnabled`, absent = OFF) and its cap
* (`gitFetchIntervalSeconds`, seconds between runs). Read FRESH on every tick by the scheduler, so a live
* toggle takes effect on the next tick and turning it off actually stops the fetching. A missing file is
* the defaults — OFF — but any other read or parse failure rejects, for the same reason as
* {@link readKeepWarmSettingsOrThrow}: settings.json is rewritten in place, so a read can land mid-write,
* and a fallback kept from it would hold the feature off until the next settings change.
* the defaults (OFF), but any other read or parse failure rejects and the scheduler skips that tick rather
* than deciding from defaults. settings.json is replaced atomically (a temp file renamed into place, see
* settings-writer.ts), so such a failure is a real read error or a file that does not parse (a hand edit),
* never a write in progress, and the scheduler logs it once rather than every tick.
*/
export async function readGitFetchSettings(): Promise<GitFetchSettings> {
let text: string;
@@ -1190,7 +1191,20 @@ export async function readGitFetchSettings(): Promise<GitFetchSettings> {
if ((err as NodeJS.ErrnoException).code === 'ENOENT') return gitFetchSettingsFrom({});
throw err;
}
return gitFetchSettingsFrom(JSON.parse(text) as Record<string, unknown>);
return gitFetchSettingsFrom(parseSettingsText(text));
}
/**
* settings.json's text for the two readers above, which reject a file that does not parse. The parser's
* own message is never repeated, as in settings-writer.ts: V8 quotes the text around the fault, settings.json
* can hold an API key (`voiceSettings.apiKey`), and both callers log the error they get.
*/
function parseSettingsText(text: string): Record<string, unknown> {
try {
return JSON.parse(text) as Record<string, unknown>;
} catch {
throw new Error(`${SETTINGS_PATH} is not valid JSON`);
}
}
function keepWarmSettingsFrom(settings: Record<string, unknown>): KeepWarmSettings {