Skip to content

Windows raw-print errors show raw PowerShell CLIXML progress noise to merchants #885

Closed

Description

@itsbkm

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) calls describeWindowsRawPrintFailure(err, ...) on failure, which calls sanitizePowerShellStderr(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:
    1. 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 during Add-Type module loading ("Preparing modules for first use.", triggered by the WINSPOOL_HELPER_SCRIPT's Add-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.
    2. 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, so errorMatches stays empty and the code falls back to only stripping a leading #<CLIXML header (lines 193-197) — which does nothing for embedded/non-leading <Objs>...</Objs> blocks.

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

  1. added a commit that references this issue on Sep 27, 2026
    bfffef9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions