Repository navigation
fix: force utf-8 output from windows powershell print helpers - #802
Conversation
Windows PowerShell 5.1 writes redirected stdout/stderr using the console/OEM code page, so FloCafe's UTF-8 decode turned accented diagnostics from Spanish and Portuguese systems into replacement characters before they reached the UI and support tickets. The raw-print and detection helpers now install UTF-8 stream writers (and the console output encoding where one exists) before doing any work, and silence the module-loading progress record that only added localized framing to printer errors. Fixes #790
|
Warning Review limit reachedNext included review available in 23 seconds. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository: FreeOpenSourcePOS/FloCafe/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
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 |
|
SummaryCoverage spans Windows printing behavior across successful jobs, offline and setup-failure handling, printer detection, concurrent requests, command encoding, and readable accented error messages. It includes normal flows plus edge cases around failures, concurrency, Unicode text, and preserving useful printer details, with no application regressions identified. Safe to merge — the exercised printing and detection behaviors are healthy, and no failures are attributable to this PR. The observed environment limitation around live offline printing is not a merge blocker. Tests run by Ito
Tip Reply with @itoqa to send us feedback on this test run. |
|
Diff SummaryCoverage focused on business rules and edge-case failure handling: printer errors remain useful, bounded, and free of sensitive command or file-path details, while printer metadata and order-support classifications remain intact. Live checkout and POS behavior was largely unavailable because the application remained in first-run setup, so those user flows were not fully exercised. Safe to merge — no regressions, new failures, or PR-attributable still-failing tests were identified, and the focused behavior checks passed. The setup-blocked checkout and POS observations are environment limitations rather than merge blockers and can be flagged for follow-up. Tests run by Ito
Tip Reply with @itoqa to send us feedback on this test run. |

Problem
Windows printer support reports from Spanish- and Portuguese-language systems contain Unicode replacement characters in PowerShell diagnostics (
Excepci?n,m?dulos). The corruption is already present in the submitted support message, so it affects both the UI printer error and the support ticket payload. Reported on receipt and KOT Windows raw-spooler paths, FloCafe 3.5.1 - 3.8.1.Fixes #790
Confirmed root cause
main/printers/thermal.tsbuilds both Windows PowerShell helpers and runs them as:Two independent facts produce the lossy result:
$ErrorActionPreference, never a stream encoding.encoding: 'utf8'. Single-byte0xF3(ó) is not valid UTF-8, so Node replaces it with U+FFFD. This is irreversible by the timesanitizePowerShellStderr()sees the string - no downstream sanitization can restore the character, which matches the issue's "cannot be recovered" note.The corrupted text that reaches users is the helper's own thrown exception message (
Excepción al llamar a SendRaw) plus the PowerShell progress recordPreparing modules for first use, which is localized and is framing rather than a device reason.What changed
main/printers/thermal.ts:POWERSHELL_UTF8_PRELUDE, prefixed to both helper scripts (detection and raw print) through a newwindowsPowerShellCommandArgs(script)builder, so there is a single place where the transport contract is defined:$ProgressPreference = 'SilentlyContinue'removes the localized "Preparing modules for first use" progress framing that was polluting printer errors.System.Text.UTF8Encodingwriter is installed over[Console]::OpenStandardOutput()/[Console]::OpenStandardError()withAutoFlush, and[Console]::OutputEncodingis set, so the helper releases UTF-8 bytes even on a non-UTF-8 console code page. The whole block is wrapped intry { } catch { }on purpose: it is best-effort and can never break printing or change control flow.[Console]::Error.Flush()beforeexit 1so the localized reason is not lost at process teardown.-EncodedCommandconstruction.Why this is the smallest safe fix
sanitizePowerShellStderr(),classifyPrintFailure(), the printing flow, the API contract, or the support pipeline.powershellcall sites inmain/(verified with a repo-wide search).encoding: 'utf8'was already correct given a UTF-8 producer, so the decoder was left alone rather than adding a code-page detection layer.Reproduction before the fix
Windows PowerShell 5.1 is not available on the development machine (macOS), so the failure was reproduced at the byte boundary instead of on a Spanish Windows host, using the real
printViaUSB()transport with a stubpowershellonPATHthat writes exact bytes to stderr:FLO_FAKE_PS_STDERR_PAYLOADbytes are decoded as UTF-8 while the transmitted script has no stream contract, so the new suite fails onthe helper switches its writers to UTF-8withAssertionError [ERR_ASSERTION], and the diagnostics assertions cannot hold.Excepción(0xF3) fed through the boundary comes back containing U+FFFD - the corruption is irreversible, which is why the producer must be fixed and not the decoder.Limitation stated plainly: no run on a real Windows PowerShell 5.1 host was performed in this environment.
Verification after the fix
npx ts-node --transpile-only -P tests/tsconfig.json tests/windows-print-stderr.test.tsnpm run test:printer(includestest:printer-api,test:printer-ipc)npm run test:thermal-capabilitiesnpm run test:print-documentnpm run test:print-kernelnpm run lintnpm run buildgit diff --checkNot run: full
npm test(150+ suites, disproportionate to a two-file printing change) and no run on real Windows PowerShell 5.1 hardware.Regression tests added (
tests/windows-print-stderr.test.ts)The existing cases all start from JavaScript strings, which is what hid the bug. The new
runEncodingRegression()block drives the real subprocess boundary:Excepción ... SendRaw) and Portuguese (Não foi possível ... economizado) UTF-8 bytes written to stderr reachdetailbyte-for-byte, with explicit assertions that neither U+FFFD nor?substitution appears._x000D__x000A_escapes) survive the existing framing cleanup with accents intact.Printer is offline->failureClass: "offline").Existing
sanitizePowerShellStderr()/classifyPrintFailure()cases were left untouched and still pass.Risk notes
try { } catch { }.printViaUSB()is covered through both receipt and KOT dispatch, so both reported surfaces share the corrected transport.main/printers/thermal.tsis possible but the change is confined to one prelude constant, one builder, two call sites, and two flush lines.