Repository navigation
fix: order 500s and PowerShell CLIXML noise in support tickets - #886
Conversation
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]>
|
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 configurationConfiguration used: Repository: FreeOpenSourcePOS/FloCafe/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review. 📝 WalkthroughWalkthroughThe changes sanitize PowerShell stderr that contains CLIXML progress records and assign HTTP 4xx statuses to product validation errors in order creation and item addition. ChangesWindows Print Error Sanitization
Order Validation HTTP Statuses
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to 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 ReviewSecurity architecture risk: 🔵 Low · up to 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 Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation 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.
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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 |
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.
Summary
Two production support tickets exposed real bugs, both traced from live FloAdmin ticket data:
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.Add-Type) appended after the real error text, both in the UI and in the text sent with support tickets.sanitizePowerShellStderronly cleaned CLIXML behind a leading#< CLIXMLmarker and only extracted<S S="Error">content, so progress-record blocks (<Obj S="progress">) passed straight through.Changes
main/routes/orders.ts: attachstatusCode: 404/400to 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:sanitizePowerShellStderrnow also triggers on embedded<Objscontent (not only a leading#< CLIXMLheader), 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— cleannpm run test:thermal-capabilities— all passing, including new regression casenpm 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