Repository navigation
Conversation
listWindowsFonts() spawned powershell.exe by bare name, which resolves to the 5.1 launcher that Group Policy can block on managed hosts, silently degrading the font picker to 5 hardcoded fallbacks. Probe pwsh.exe first, then the absolute Windows PowerShell path, and log the real spawn error before the fallback. Verified with 3 new tests (candidate chain order, absolute-path fallback, all-fail logging) plus updated win32 timeout semantics; oxlint and oxfmt clean.
Greptile SummaryThis PR fixes a silent degradation on Windows where Group Policy blocking
Confidence Score: 4/5Safe to merge. The change is Windows-only and runtime-guarded; macOS and Linux paths are byte-identical. The candidate chain is constructed from static, trusted values with no shell interpolation. The implementation is correct and well-tested. The only notable fragility is that Files Needing Attention: No files require special attention.
|
| Filename | Overview |
|---|---|
| src/main/system-fonts.ts | Adds windowsPowerShellCandidates() and execFileTextFirst() to try pwsh.exe before the absolute PowerShell 5.1 path; adds a logging .catch() in listWindowsFonts() that re-throws so the outer fallback still applies. One minor edge case: execFileTextFirst throws undefined if called with an empty commands list. |
| src/main/system-fonts.test.ts | Adds three Windows-specific unit tests (pwsh success, pwsh fallback to absolute path, both-fail + warn log), updates the timeout helper to accept an expectedKills count, and adjusts the win32 timeout test to account for the new 2-candidate chain (30s total worst case). |
Sequence Diagram
sequenceDiagram
participant C as listSystemFontFamilies
participant L as listWindowsFonts
participant F as execFileTextFirst
participant P1 as pwsh.exe
participant P2 as powershell.exe (absolute)
C->>L: (win32 only)
L->>F: "candidates=[pwsh.exe, C:\Windows\...\powershell.exe]"
F->>P1: execFileText(pwsh.exe, 15s timeout)
alt pwsh succeeds
P1-->>F: stdout
F-->>L: output
L-->>C: sorted font list
else pwsh fails / GP-blocked
P1-->>F: Error (ENOENT / UNKNOWN)
F->>P2: execFileText(absolute path, 15s timeout)
alt absolute path succeeds
P2-->>F: stdout
F-->>L: output
L-->>C: sorted font list
else both fail
P2-->>F: Error
F-->>L: throws lastError
L-->>L: .catch() → console.warn + rethrow
L-->>C: throws
C-->>C: .catch() → fallbackFonts()
end
end
Reviews (1): Last reviewed commit: "fix(fonts): prefer pwsh and log failures..." | Re-trigger Greptile
| let lastError: unknown | ||
| for (const command of commands) { |
There was a problem hiding this comment.
execFileTextFirst throws undefined if commands is empty, because lastError is never assigned. Today windowsPowerShellCandidates() always returns two entries so this can't happen at runtime, but the contract is fragile if the function is reused or the candidates list is ever conditionally filtered. Initialising lastError to a descriptive Error makes the failure mode explicit and avoids a silent throw undefined.
| let lastError: unknown | |
| for (const command of commands) { | |
| let lastError: unknown = new Error('execFileTextFirst called with empty commands list') | |
| for (const command of commands) { |
| .catch((error: unknown) => { | ||
| // Why: a GP-blocked PowerShell used to degrade to 5 hardcoded fonts with | ||
| // no trace; surface the real spawn error so managed hosts are diagnosable. | ||
| console.warn('[system-fonts] failed to enumerate Windows fonts, using fallback:', error) |
There was a problem hiding this comment.
The log message says "using fallback" but this
.catch() immediately re-throws — the fallback is applied by the outer handler in listSystemFontFamilies. Someone reading the main-process log could be confused about where control actually ends up. Rewording avoids that ambiguity.
| console.warn('[system-fonts] failed to enumerate Windows fonts, using fallback:', error) | |
| console.warn('[system-fonts] failed to enumerate Windows fonts, falling back to defaults:', error) |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
📝 WalkthroughWalkthroughWindows font discovery now tries PowerShell 7 and the absolute Windows PowerShell 5.1 executable in order. It retries candidates and returns the first successful result. If all candidates fail, it logs the spawn error and rethrows it. Tests cover successful execution, fallback execution, hardcoded fallback output, timeout behavior, retry counts, process termination, and warning output. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/system-fonts.ts (1)
93-108: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winConsider bounding total worst-case wait across candidates.
execFileTextFirstgives every candidate the fulltimeoutMsbefore moving to the next one. On Windows, this doubles the worst-case wait before the fallback fonts are returned (confirmed by the test suite: 30s for two candidates vs. 15s for a single candidate on other platforms). If a Group-Policy-blocked PowerShell process hangs instead of failing fast (rather than the fast ENOENT/permission-error case), a user opening Settings on a managed Windows host now waits up to twice as long before seeing any fonts.Split the timeout budget across candidates, or cap the total elapsed time, so adding a retry candidate does not multiply the worst-case latency.
♻️ Example: split the timeout budget across candidates
async function execFileTextFirst( commands: string[], args: string[], maxBuffer: number, timeoutMs = SYSTEM_FONT_LIST_TIMEOUT_MS ): Promise<string> { let lastError: unknown + const perCommandTimeoutMs = Math.max(1, Math.floor(timeoutMs / commands.length)) for (const command of commands) { try { - return await execFileText(command, args, maxBuffer, timeoutMs) + return await execFileText(command, args, maxBuffer, perCommandTimeoutMs) } catch (error) { lastError = error } } throw lastError }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d68de06b-0184-4ca7-8ab8-0c6dd3b3f1e6
📒 Files selected for processing (2)
src/main/system-fonts.test.tssrc/main/system-fonts.ts
Summary
Fixes #11771
When Group Policy blocks Windows PowerShell 5.1, the font picker silently degraded to the 5 hardcoded fallback fonts.
listWindowsFonts()spawnedpowershell.exeby bare name, which fails withspawn UNKNOWN (errno -4094)on a GP-blocked host — and the error was swallowed by the fallback path with no log.This PR:
pwsh.exefirst, then the absolute Windows PowerShell 5.1 path (resolved from%WINDIR%, defaulting toC:\Windows) — so the enumeration survives GP policy and also works on PowerShell 7-only installs.console.warnbefore falling back, so silent degradation is now visible in the main-process log.Screenshots
No visual change.
Testing
pnpm lint(full, incl. localization coverage audit)pnpm typecheck(full, all three tsconfig projects)pnpm test(targeted:src/main/system-fonts.test.ts7/7 — 3 new Windows cases + updated win32 timeout case;src/main/ipc/settings.test.ts28/28). Full suite not run locally; CI covers it.pnpm build(not run; no build-affecting surface)AI Review Report
Reviewed by a reliability lens against the exact candidate diff (tests + implementation):
pwsh.exeis always tried first and the chain stops on first success; the absolute 5.1 path is a fallback, so PowerShell 7-first hosts keep the faster path.execFileTextsignature unchanged;settingsIPC consumers oflistSystemFontFamiliesunaffected.system_profiler) and linux (fc-list) paths are untouched; on non-Windows hosts behavior is byte-identical.Security Audit
execFile(no shell interpolation).%WINDIR%resolution is environment-driven with a fixed safe default (C:\Windows); the candidate list contains only the two well-known Windows shells.Notes
Windows-only fix, verified through mocked
execFilein unit tests — no Windows host connected to validate against a real GP-blocked machine.Root cause of the silent degradation: the previous
catchsubstituted the fallback list without logging, so the failure was invisible to users and maintainers alike.X: @umillann