fix(gsd): suppress repeated frontmatter YAML parse warnings

logWarning fired on every preferences load when YAML was malformed,
flooding the TUI. Now warns at most once per session with a suppression
notice.

Closes #3376

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Tibsfox 2026-04-06 19:33:55 -07:00
parent b4c6229360
commit db19c2e67a

View file

@ -201,9 +201,10 @@ function loadPreferencesFile(path: string, scope: "global" | "project"): LoadedG
let _warnedUnrecognizedFormat = false;
/** @internal Reset the warn-once flag — exported for testing only. */
/** @internal Reset the warn-once flags — exported for testing only. */
export function _resetParseWarningFlag(): void {
_warnedUnrecognizedFormat = false;
_warnedFrontmatterParse = false;
}
/** @internal Exported for testing only */
@ -235,6 +236,7 @@ export function parsePreferencesMarkdown(content: string): GSDPreferences | null
return null;
}
let _warnedFrontmatterParse = false;
function parseFrontmatterBlock(frontmatter: string): GSDPreferences {
try {
const parsed = parseYaml(frontmatter);
@ -243,7 +245,11 @@ function parseFrontmatterBlock(frontmatter: string): GSDPreferences {
}
return parsed as GSDPreferences;
} catch (e) {
logWarning("guided", `YAML parse error in frontmatter block: ${(e as Error).message}`);
// Warn at most once per session to avoid flooding TUI (#3376)
if (!_warnedFrontmatterParse) {
_warnedFrontmatterParse = true;
logWarning("guided", `YAML parse error in preferences frontmatter (suppressing further): ${(e as Error).message}`);
}
return {} as GSDPreferences;
}
}