Repository navigation
Description
Summary
When a Windows raw-print job fails (main/printers/thermal.ts, printViaUSBWindows), the merchant/staff-facing error message can be polluted with raw, unparsed PowerShell CLIXML progress-stream serialization instead of just the clean exception text. This garbled message is shown in the UI and sent verbatim in support tickets.
Real example (from a production support ticket)
Exception calling "SendRaw" with "2" argument(s): "printer is set to 'Use Printer Offline' in Windows"
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0">...<AV>Preparing modules for first use.</AV>...</Objs>
Only the first line is the real, useful error; everything after it is PowerShell CLIXML noise.
Root cause
printViaUSBWindows(main/printers/thermal.ts:2815) callsdescribeWindowsRawPrintFailure(err, ...)on failure, which callssanitizePowerShellStderr(err.stderr)(main/printers/thermal.ts:2779) to clean the raw stderr before showing it to the user.sanitizePowerShellStderr(main/printers/thermal.ts:168-198) has two gaps:- Early-return guard:
if (!raw.includes('#< CLIXML')) return raw;(line 171) skips all cleanup unless the string contains that exact literal marker. The progress-record CLIXML emitted duringAdd-Typemodule loading ("Preparing modules for first use.", triggered by theWINSPOOL_HELPER_SCRIPT'sAdd-Type -TypeDefinition ...at runtime) does not always carry that leading marker, so the guard fails and the raw CLIXML passes straight through unfiltered — exactly what's shown above. - Even when the guard passes, the extraction regex only matches
<S S="Error">...</S>(line 176) — real PowerShell error-stream CLIXML. Progress records serialize as<Obj S="progress" RefId="...">with a nested<PR N="Record">, a different shape the regex never matches, soerrorMatchesstays empty and the code falls back to only stripping a leading#<CLIXMLheader (lines 193-197) — which does nothing for embedded/non-leading<Objs>...</Objs>blocks.
- Early-return guard:
This is deterministic given the current code, not an environment fluke: $ProgressPreference = 'SilentlyContinue' (set in POWERSHELL_UTF8_PRELUDE, line 518) does not reliably suppress this specific engine-level "module loading" progress record on PowerShell 5.1, so any Windows raw-print failure that triggers Add-Type's first-use module load will get this noise appended to the real error, every time.
Fix
Make sanitizePowerShellStderr strip any <Objs...>...</Objs> / #< CLIXML occurrence found anywhere in the string (not only via the leading-marker guard, and not only <S S="Error"> content), keeping just the plain-text lines around it.
Impact
User-facing (and support-ticket) print-failure messages are harder to read and can look like a crash dump instead of a clear "printer is offline" message — this affects triage speed for every Windows raw-print failure that happens to trip the module-loading progress record, not just this one ticket.
Activity
fix: order 500s and PowerShell CLIXML noise in support tickets (FreeO…