You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix the confirmed non-product bug tracked in #1640 where PrintersSettingsTab.deletePrinterHw swallows the backend HTTP 409 error reason when deleting the sole default printer (showing a generic "Failed to delete printer" toast), and main/routes/printers.ts logs expected 4xx errors as [API] Internal error / res.locals.postHogError. Keep the existing 409 policy intact and ship a minimal fix with regression tests via a PR that closes #1640.
What Changed
Updated deletePrinterHw in frontend/src/components/settings/PrintersSettingsTab.tsx to format caught errors with printerErrorMessage(err, t('printerDeleteFailed')) so backend error reasons (including HTTP 409 responses) are surfaced in the error toast while preserving the generic fallback.
Updated PUT /:id and DELETE /:id in main/routes/printers.ts to return expected 4xx errors (400 <= statusCode < 500) before assigning res.locals.postHogError or logging [API] Internal error:.
Added regression tests in tests/printer-api.test.ts and tests/printer-error-toast-clarity.test.ts covering 409 response payloads, telemetry/logging suppression for expected 409s, and delete-error toast rendering in PrintersSettingsTab.
Closes #1640
Risk Assessment
✅ Low: The change is a minimal, well-bounded fix that surfaces backend 409 error reasons in printer deletion toasts, suppresses internal-error logging and PostHog error capture for expected 4xx responses in printer PUT/DELETE routes, and includes targeted regression tests with separate DELETE and PUT log snapshots.
Testing
Ran the targeted backend and frontend printer regression suites (test:printer-api and printer-error-toast-clarity.test.ts), built the backend and static desktop frontend, and drove all four scenarios live in headless Chromium against an isolated FloCafe server instance on localhost ports 13001-13003, capturing UI screenshots and live server logs; all checks and scenarios passed with no issues.
Live validation: ✅ go - 4 of 4 scenarios driven live against the product
Scenario
Result
Live
Evidence
Deleting the sole default printer in Settings > Printers surfaces the backend HTTP 409 reason in the error toast and keeps the printer intact
Evidence: Live Express API 409 responses and stderr verification (no [API] Internal error)
DELETE /api/printers/b41cb87f-4ae9-4763-a238-a85e1c3d17b9 -> HTTP 409 {"error":"Cannot delete the only default printer"}
PUT /api/printers/b41cb87f-4ae9-4763-a238-a85e1c3d17b9 {"is_default":false} -> HTTP 409 {"error":"At least one printer must remain default"}
Server stderr lines during both 409 requests (0):
(none)
Contains "[API] Internal error": false
DELETE /api/printers/b41cb87f-4ae9-4763-a238-a85e1c3d17b9 -> HTTP 409 {"error":"Cannot delete the only default printer"}
PUT /api/printers/b41cb87f-4ae9-4763-a238-a85e1c3d17b9 {"is_default":false} -> HTTP 409 {"error":"At least one printer must remain default"}
Server stderr lines during both 409 requests (0):
(none)
Contains "[API] Internal error": false
Evidence: Full isolated E2E server stdout/stderr log during live verification
🚨 tests/printer-api.test.ts:341 - In Test 6, loggedErrors.length = 0 at line 341 clears the captured console.error output from the DELETE /api/printers/:id request before line 363 asserts !loggedErrors.some((msg) => msg.includes('[API] Internal error')) for DELETE. As a result, line 363 actually checks the PUT request's logs (identical to line 380), so a regression where DELETE logs [API] Internal error would pass undetected. Snapshot deleteLoggedErrors = [...loggedErrors] before clearing loggedErrors (or use separate arrays for DELETE and PUT) and assert against deleteLoggedErrors at line 363.
🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
Live validation: ✅ go - 4 of 4 scenarios driven live against the product
Scenario
Result
Live
Evidence
Deleting the sole default printer in Settings > Printers surfaces the backend HTTP 409 reason in the error toast and keeps the printer intact
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Walkthrough
Printer update and delete handlers now return 4xx errors without internal-error tracking. Printer delete failures use the existing error formatter to show backend error text when available, with a generic fallback.
Changes
Printer error handling
Layer / File(s)
Summary
Handle printer API client errors main/routes/printers.ts, tests/printer-api.test.ts
The update and delete handlers return 4xx errors before internal-error tracking and logging. Tests verify the 409 responses for refusing to delete or unset the default printer, and check that no internal error is recorded or logged.
The delete failure toast uses printerErrorMessage, with printerDeleteFailed as the fallback. Tests check backend error text, the generic network-error fallback, and that failures do not show a success toast.
Issue 1645 — It concerns error details from the same printerErrorMessage helper, but for WebUSB test-print failures. This change covers printer deletion and does not address the test-print path.
Merge Risk: Minimal · previous review ec68a
Deleting a printer now shows the backend's reason for failure in the toast, such as when it is the only default printer. Expected 4xx printer responses are no longer reported as internal errors. The changes are small and reversible, and no merge-blocking risk was found.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title "fix(printers): surface 409 on sole delete" matches the main change: the delete-printer toast now shows the backend 409 reason when deleting the sole default printer, and expected 4xx respon…
Description check
The description follows the repository template closely. It includes an Intent (issue linkage), Summary of changes, Risk Assessment, Testing with exact commands and results, screenshots, and a 'Closes…
Linked Issues check
[#1640] Objective 1: deletePrinterHw must pass the caught error to printerErrorMessage(err, t('printerDeleteFailed')). The AI-generated summary for PrintersSettingsTab.tsx reports this change (+2/-2).…
Out of Scope Changes check
The change set, as listed in the summary, covers four files: PrintersSettingsTab.tsx, main/routes/printers.ts, tests/printer-api.test.ts, and tests/printer-error-toast-clarity.test.ts. The source chan…
Full details: Title check
Explanation
The title "fix(printers): surface 409 on sole delete" matches the main change: the delete-printer toast now shows the backend 409 reason when deleting the sole default printer, and expected 4xx responses are no longer logged as internal errors. It is concise, uses a conventional prefix, and names the affected area. It omits the logging change, which is a secondary aspect and acceptable.
Full details: Description check
Explanation
The description follows the repository template closely. It includes an Intent (issue linkage), Summary of changes, Risk Assessment, Testing with exact commands and results, screenshots, and a 'Closes #1640' reference. It does not fill in the template's Scope, Compatibility and data safety, Cross-cutting surfaces table, Developer documentation checkbox, or Contributor checklist sections. These are non-critical omissions, so the description is mostly complete.
Full details: Linked Issues check
Explanation
[#1640] Objective 1: deletePrinterHw must pass the caught error to printerErrorMessage(err, t('printerDeleteFailed')). The AI-generated summary for PrintersSettingsTab.tsx reports this change (+2/-2). The fallback string is kept. The new test in tests/printer-error-toast-clarity.test.ts checks that a 409 body reaches the toast and that a transport error without a body shows the generic text. Objective 2: expected 4xx responses must not reach the internal-error path. The summary for main/routes/printers.ts reports that PUT /:id and DELETE /:id return 4xx errors before setting res.locals.postHogError or logging [API] Internal error. The PR description gives live evidence: 409 responses on DELETE and PUT, with server stderr containing no '[API] Internal error'. Objective 3: the 409 status policy stays unchanged. The summary and the PR description both state this. Limits: the whole-PR diff could not be read (changed blobs missing from checkout). The head file read was truncated before the DELETE handler, so the exact hunks were not checked directly. The PASS relies on the summary and the live evidence.
Full details: Out of Scope Changes check
Explanation
The change set, as listed in the summary, covers four files: PrintersSettingsTab.tsx, main/routes/printers.ts, tests/printer-api.test.ts, and tests/printer-error-toast-clarity.test.ts. The source changes (+2/-2 frontend, +6/-0 backend) map directly to #1640. The test changes support those objectives. No unrelated file or feature change is reported. The 400 order error in the PR log is not attributed to printer code and is not a change in this PR. Limit: the diff itself was unavailable, so the file list comes from the summary only.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.
Surface printer deletion conflicts without logging expected 4xx errors
🐞 Bug fix🧪 Tests🕐 20-40 Minutes
AI Description
• Show the backend’s reason when printer deletion is refused, with a generic fallback for transport
failures.
• Return expected printer PUT and DELETE 4xx responses without internal-error logging or PostHog
capture.
• Add regression tests for conflict payloads, logging suppression, and deletion toasts.
Merge Risk 🟢 Low
Blast radius 🟢 Low💥 1 capability
1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
The API conflict response and settings toast jointly affect one bounded printer-configuration workflow: rejected default-printer changes are returned by the printer route and presented by the printer settings UI.
No separate printing, ordering, or payment behavior is changed.
Behavioral complexity 🟢 Low🧩 Straightforward
Before, expected 4xx exceptions entered the generic logging and telemetry path, while deletion showed only its fallback message.
After, 4xx status errors return directly and deletion extracts a string error from the Axios response.
The new correctness condition is a simple status-range branch plus fallback precedence: preserve the API status/message, avoid internal-error reporting for expected conflicts, and use the backend reason only when it is a nonempty string.
Existing printer validation, transactions, and error-extraction helpers are reused rather than introducing new state or ordering protocols.
Potential damage 🟢 Low🩹 Reversible
If this behavior regresses, users may receive only a generic deletion failure or operators may get noisy internal-error reporting; rejected printer state remains intact and retry or code rollback restores feedback.
No persistent printer data or external effect is introduced by these changes.
Reverting restores the previous handling; correcting the configuration or retrying remains available.
sequenceDiagram
actor User
participant UI as Printer Settings
participant Routes as Printer Routes
participant DB as Printer DB
participant Formatter as Error Formatter
participant Telemetry as Error Telemetry
User->>UI: Delete printer
UI->>Routes: DELETE printer
Routes->>DB: Check default invariant
DB-->>Routes: Result or 409 conflict
alt Expected 4xx
Routes-->>UI: Status and error reason
UI->>Formatter: Format deletion error
Formatter-->>UI: Reason or fallback
UI-->>User: Show error toast
else Unexpected error
Routes->>Telemetry: Capture and log error
Routes-->>UI: Error response
end
Loading
High-Level Assessment
Keep the localized fix. Reusing the settings component’s existing error formatter preserves its fallback behavior, while handling expected 4xx responses before telemetry leaves the default-printer policy unchanged. A shared route error handler would be broader than this printer-specific issue requires.
Files changed (4) +256 / -4
Bug fix (2) +8 / -2
PrintersSettingsTab.tsxShow the API reason for failed printer deletion+2/-2
Show the API reason for failed printer deletion
• The deletion catch block now uses the component’s existing printer error formatter. It displays a backend reason when present and retains the translated generic fallback otherwise.
printers.tsExclude expected PUT and DELETE 4xx responses from internal-error telemetry+6/-0
Exclude expected PUT and DELETE 4xx responses from internal-error telemetry
• Both route handlers now return caught 4xx errors before setting postHogError or logging an internal error. Unexpected errors retain the existing logging and response path.
printer-api.test.tsVerify printer conflict responses and telemetry suppression+59/-2
Verify printer conflict responses and telemetry suppression
• The API test checks the 409 reasons for deleting or unsetting the sole default printer. It separately snapshots DELETE and PUT logs and checks that neither response sets postHogError or logs an internal error.
printer-error-toast-clarity.test.tsCover deletion conflict and transport-failure toasts+189/-0
Cover deletion conflict and transport-failure toasts
• A component-level regression test invokes the rendered delete button with mocked API failures. It checks that a 409 reason appears in the toast, an error without an API body uses the generic fallback, and neither failure shows a success toast.
khaira777
changed the title
fix: surface printer delete 409 errors and skip internal error logging for 4xx responses
fix(printers): surface 409 on sole delete
Nov 27, 2026
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
The PR makes printer-delete errors clearer without changing the existing 409 policy.
Printer deletion toasts show the server’s reason when it refuses a request.
Printer update and delete refusals no longer count as internal errors.
No behavioral defect was found. One new test comment must be adjusted to meet the repository’s comment rule.
Checks were limited to source review; builds, tests, and browser checks were not run.
Acknowledged fix: khaira777’s PR description notes that DELETE assertions previously inspected PUT logs. The current code saves separate DELETE and PUT snapshots.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Fix the confirmed non-product bug tracked in #1640 where
PrintersSettingsTab.deletePrinterHwswallows the backend HTTP 409 error reason when deleting the sole default printer (showing a generic"Failed to delete printer"toast), andmain/routes/printers.tslogs expected 4xx errors as[API] Internal error/res.locals.postHogError. Keep the existing 409 policy intact and ship a minimal fix with regression tests via a PR that closes#1640.What Changed
deletePrinterHwinfrontend/src/components/settings/PrintersSettingsTab.tsxto format caught errors withprinterErrorMessage(err, t('printerDeleteFailed'))so backend error reasons (including HTTP 409 responses) are surfaced in the error toast while preserving the generic fallback.PUT /:idandDELETE /:idinmain/routes/printers.tsto return expected4xxerrors (400 <= statusCode < 500) before assigningres.locals.postHogErroror logging[API] Internal error:.tests/printer-api.test.tsandtests/printer-error-toast-clarity.test.tscovering 409 response payloads, telemetry/logging suppression for expected 409s, and delete-error toast rendering inPrintersSettingsTab.Closes
#1640Risk Assessment
✅ Low: The change is a minimal, well-bounded fix that surfaces backend 409 error reasons in printer deletion toasts, suppresses internal-error logging and PostHog error capture for expected 4xx responses in printer PUT/DELETE routes, and includes targeted regression tests with separate DELETE and PUT log snapshots.
Testing
Ran the targeted backend and frontend printer regression suites (
test:printer-apiandprinter-error-toast-clarity.test.ts), built the backend and static desktop frontend, and drove all four scenarios live in headless Chromium against an isolated FloCafe server instance on localhost ports 13001-13003, capturing UI screenshots and live server logs; all checks and scenarios passed with no issues.Evidence: Live Express API 409 responses and stderr verification (no [API] Internal error)
DELETE /api/printers/b41cb87f-4ae9-4763-a238-a85e1c3d17b9 -> HTTP 409 {"error":"Cannot delete the only default printer"} PUT /api/printers/b41cb87f-4ae9-4763-a238-a85e1c3d17b9 {"is_default":false} -> HTTP 409 {"error":"At least one printer must remain default"} Server stderr lines during both 409 requests (0): (none) Contains "[API] Internal error": falseEvidence: Full isolated E2E server stdout/stderr log during live verification
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 1 issue found → auto-fixed ✅
tests/printer-api.test.ts:341- In Test 6,loggedErrors.length = 0at line 341 clears the capturedconsole.erroroutput from theDELETE /api/printers/:idrequest before line 363 asserts!loggedErrors.some((msg) => msg.includes('[API] Internal error'))for DELETE. As a result, line 363 actually checks thePUTrequest's logs (identical to line 380), so a regression whereDELETElogs[API] Internal errorwould pass undetected. SnapshotdeleteLoggedErrors = [...loggedErrors]before clearingloggedErrors(or use separate arrays for DELETE and PUT) and assert againstdeleteLoggedErrorsat line 363.🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
npm run test:printer-apinpx tsx --tsconfig tests/tsconfig.json -r ./tests/register-tsx.cjs tests/printer-error-toast-clarity.test.tsnpm run build && npm run build:frontendLive headless Chromium + isolatedtests/e2e-server.cjsverification on127.0.0.1:13001-13003driving sole-default delete 409 toast, DELETE/PUT 409 server stderr check, aborted-request fallback toast, and multi-printer delete success✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
Issues
Closes #1640
Summary by CodeRabbit