Skip to content

fix: order 500s and PowerShell CLIXML noise in support tickets - #886

Merged
itsbkm merged 2 commits into
mainfrom
fix/order-500-status-codes-and-print-clixml-noise
Sep 26, 2026
Merged

itsbkm merged 2 commits into
mainfrom
fix/order-500-status-codes-and-print-clixml-noise

Conversation

@itsbkm

@itsbkm itsbkm commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Two production support tickets exposed real bugs, both traced from live FloAdmin ticket data:

  • Order creation returns HTTP 500 instead of a 4xx for ordinary validation failures #884 — Order creation returned a generic HTTP 500 for ordinary, expected failures (stale product reference, invalid price, invalid add-on quantity) because those throws had no statusCode, so they fell into the catch-all's 500 default instead of a proper 404/400. The same unguarded pattern was duplicated in both the order-creation route and the add-items-to-order route (6 call sites total); this fixes both.
  • Windows raw-print errors show raw PowerShell CLIXML progress noise to merchants #885 — Windows raw-print failures could show raw PowerShell CLIXML progress-stream noise (from module auto-loading during Add-Type) appended after the real error text, both in the UI and in the text sent with support tickets. sanitizePowerShellStderr only cleaned CLIXML behind a leading #< CLIXML marker and only extracted <S S="Error"> content, so progress-record blocks (<Obj S="progress">) passed straight through.

Changes

  • main/routes/orders.ts: attach statusCode: 404/400 to the product-not-found / invalid-price / invalid-add-on-quantity throws in both order routes, matching the existing pattern already used elsewhere in the file (Object.assign(new Error(...), { statusCode })).
  • main/printers/thermal.ts: sanitizePowerShellStderr now also triggers on embedded <Objs content (not only a leading #< CLIXML header), and strips any <Objs...>...</Objs> envelope found anywhere in the buffer as a fallback when no structured <S S="Error"> text is present.
  • tests/windows-print-stderr.test.ts: added a regression case reproducing Windows raw-print errors show raw PowerShell CLIXML progress noise to merchants #885's exact ticket text.

Test plan

  • npm run lint — 0 errors (pre-existing warnings only)
  • npm run build — clean
  • npm run test:thermal-capabilities — all passing, including new regression case
  • npm run test:orders-authz, test:order-item-addons, test:integration-lifecycle, test:order-item-cancel-restore — all passing (no test asserted a 500 for these paths, so no existing behavior broken by the status-code change)

Closes #884
Closes #885

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Order creation and item additions now return clearer 404 responses for missing products and 400 responses for invalid prices or add-on quantities, rather than server errors.
    • Improved cleanup of PowerShell printing errors so technical markup is removed while readable error text is retained.
  • Tests
    • Added coverage for printing errors that include progress output without the usual marker.

itsbkm and others added 2 commits September 27, 2026 00:44
Product-not-found, invalid-price, and invalid-add-on-quantity checks in
order creation and add-items-to-order threw plain Errors with no
statusCode, so the route's catch-all defaulted them to HTTP 500 and a
generic "Internal server error" instead of a specific 404/400 response.

Closes #884

Co-Authored-By: Claude Sonnet 5 <[email protected]>
sanitizePowerShellStderr only cleaned CLIXML behind a leading "#< CLIXML"
marker and only extracted <S S="Error"> content, so progress-record
CLIXML emitted by PowerShell's module auto-load (e.g. during Add-Type)
passed through unfiltered and got appended to the real error message
shown to merchants and sent in support tickets.

Closes #885

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: FreeOpenSourcePOS/FloCafe/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 23bbd319-c0ba-4895-9e89-70711fed822f

📥 Commits

Reviewing files that changed from the base of the PR and between 4a87274 and 7513659.

📒 Files selected for processing (3)
  • main/printers/thermal.ts
  • main/routes/orders.ts
  • tests/windows-print-stderr.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.


📝 Walkthrough

Walkthrough

The changes sanitize PowerShell stderr that contains CLIXML progress records and assign HTTP 4xx statuses to product validation errors in order creation and item addition.

Changes

Windows Print Error Sanitization

Layer / File(s) Summary
Sanitize CLIXML stderr
main/printers/thermal.ts, tests/windows-print-stderr.test.ts
The sanitizer recognizes <Objs> markers and removes CLIXML headers and complete envelopes in its fallback path. A regression test checks that a SendRaw exception remains without following progress-record CLIXML.

Order Validation HTTP Statuses

Layer / File(s) Summary
Set statuses for order validation errors
main/routes/orders.ts
Order creation and item addition return 404 for missing products and 400 for invalid product prices or add-on quantities.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 75136

The reported print-error cleanup and order-validation responses are addressed in the changed paths. No actionable merge risk is established by the reviewed changes.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 75136

The order endpoints retain their permission and rate-limit checks, and the print change removes diagnostic noise rather than changing printer authority. No security regression was established, but the new order responses disclose more specific errors than the previous generic responses.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The new order-response detail is reachable through the two permission-gated, rate-limited write endpoints. The supplied changes do not show a new caller, privilege, or cross-system dependency.

Security Findings and Attack Paths

  • observed — A permitted caller can now receive the requested product ID in a missing-product error or a product name in an invalid-price error. The evidence does not establish that those values are sensitive catalog data or that this is a security finding.

Trust Boundaries and Controls

  • observed — The order permission and rate-limit controls remain ahead of the changed validation branches; the existing catch handlers control which error messages cross the HTTP boundary.

Resilience and Maintainability Implications

  • observed — The Windows raw-print failure path still separates stderr-derived detail from command execution and applies command-evidence detection, payload-path redaction, and length limiting before returning or logging that detail.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description clearly explains the issues, affected files, fixes, linked work, and verification commands. It omits several required template sections: Scope, Compatibility & data safety, Screenshots… Add the missing template sections. State the intended scope and out-of-scope changes, document database, migration, user-visible, and offline/network impact, mark Screenshots as not applicable if appropriate, complete the Cross-cutting surf…
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies both primary changes: correcting order HTTP 500 responses and removing PowerShell CLIXML noise from support tickets.
Linked Issues check ✅ Passed The changes satisfy both active linked issues. For #884, main/routes/orders.ts now assigns status code 404 to missing products and 400 to invalid prices and add-on quantities in both order creation …
Out of Scope Changes check ✅ Passed The changed files remain within #884 and #885. The order-route edits implement the required client status codes. The thermal edit and its regression test implement CLIXML cleanup. No unrelated change …
Full details: Description check

Explanation

The description clearly explains the issues, affected files, fixes, linked work, and verification commands. It omits several required template sections: Scope, Compatibility & data safety, Screenshots, Cross-cutting surfaces, Developer documentation, and the Contributor checklist.

Resolution

Add the missing template sections. State the intended scope and out-of-scope changes, document database, migration, user-visible, and offline/network impact, mark Screenshots as not applicable if appropriate, complete the Cross-cutting surfaces table, select the applicable Developer documentation option, and complete the Contributor checklist.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@itsbkm
itsbkm merged commit bfffef9 into main Sep 26, 2026
16 checks passed
@itsbkm
itsbkm deleted the fix/order-500-status-codes-and-print-clixml-noise branch September 26, 2026 19:37
khaira777 added a commit that referenced this pull request Sep 26, 2026
The two assertions the four-platform matrix reported were stale, not a regression: the
diagnostic behaviour they describe is unchanged and still intended, and #886 legitimately
changed the HTTP status that behaviour is derived from. Both failures came from one
cause. Step 8 of tests/diagnostics-event.test.ts posts an order whose product_id does not
exist and then looks for the enqueued order.create.failed row by metadata.status 500, a
number it had picked up incidentally because a missing product used to be an unhandled
internal error. #886 gave that throw a 404, so the row is still enqueued, still carries the
order_insert stage, and still records the status the request produced - it simply records
404 now, the 500 lookup finds nothing, and both assertions in that step fail. Nothing in
the order-create classification changed: main/routes/orders.ts still enqueues a diagnostic
for every failed create, still reports inventory_validation only for an insufficient-stock
error, and still reports the actual HTTP status in metadata.status, which is the
documented contract the cloud-sync sanitizer accepts over the whole 100-599 range. The fix
is therefore in the assertion, not in the route, and no production code is touched here.
The brief named order.create.failed is enqueued on inventory failure as a second failure,
but that assertion passes both locally and on the CI log for the red run, so step 7 is
left exactly as it is.

The updated assertion is deliberately stronger than the one it replaces rather than merely
rewritten to match the current output. The old version pinned a magic 500 while asserting
nothing about how the reported status relates to the response. It now asserts the response
is 404, looks the row up by the status the request actually produced, and separately
asserts that the diagnostic carries that status, the order_insert stage and the item count,
so status and stage are pinned independently instead of one lookup standing in for both. I
checked it still has teeth by mutating the production code four ways and confirming red
each time: reverting #886's 404 back to a plain Error fails the 404 assertion outright,
hard-coding 500 in the diagnostic report fails the status assertions in both step 7 and
step 8, classifying every create failure as inventory_validation fails the four step 8
assertions, and hard-coding item_count fails the count assertions. The suite was red with
2 failures before this change and is green with 70 passing after it.

Two consequences of #886 are worth recording here rather than acting on, since neither is
a regression and both are outside this fix. First, the inventory_validation stage is still
chosen by exact message equality on 'Insufficient stock', so the sibling 'Product not
found' and the invalid-delta guards that adjustProductStock also throws are reported as
order_insert; that imprecision predates #886 and no assertion pins it, but it does
under-report inventory-stage failures in telemetry. Second, the matrix explains the
3-of-4-platform pattern exactly: the Windows job runs the first three pretest suites and
then the shard, and never runs test:diagnostics-event, so Windows reported success on a
suite it did not execute, and PR CI does not run it either because run-test-shard.cjs
derives its suite list from the test script while pretest is invoked separately. That is a
real coverage hole in both workflows, but widening either one is a deliberate call for a
maintainer rather than something to slip into a test-fix commit.

Verification: npm run lint (clean, 5 pre-existing frontend warnings), npm run build, and
the full local suite including pretest. On the full run tests/diagnostics-event.test.ts
goes 2 failures to none, and one unrelated suite, tests/cash-closures.test.ts, failed once
with duplicate active opening float is rejected reporting 400 where it expects 409 - it is
a different file and a separate process, it passed 320/320 in six consecutive standalone
runs and in a subsequent 169-suite shard run, and main's own CI has both core shards
green, so I read it as a pre-existing local intermittent and did not touch it. I could not
run the four-platform matrix myself; branch CI will.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant