Repository navigation
fix(export): add PDF timeout and hoist currency - #1526
Conversation
Add a 30-second rendering deadline, renderer termination handling, and window-close cleanup in renderHtmlToPdfBuffer, and hoist the currency minor-unit factor lookup out of the per-bill loop in getOrdersWithItemsForBills. Fixes #1518
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
|
ⓘ Your Qodo trial ends soon. Ask your workspace admin to set up billing to keep reviews running after the trial. Manage billing |
PR Summary by QodoAdd a PDF render deadline and avoid repeated bill currency lookups
AI Description
Diagram
High-Level Assessment
Files changed (5)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can pick a display mode instead of tweaking every Display option by hand |
Fixes #1518
Intent
Approve the two surgical export fixes and defer the 366-day increase:
What Changed
render-process-goneandclosed) inrenderHtmlToPdfBuffer, destroying the hiddenBrowserWindowon timeout and cleaning up timers, listeners, and staged HTML files infinally.getCurrencyMinorUnitFactor(getTenantCurrency())outside the per-bill loop ingetOrdersWithItemsForBillsso tenant currency settings are read once per batch call instead of once per bill.Risk Assessment
✅ Low: The changes cleanly add a 30-second rendering deadline (excluding save dialog time) with full window/listener/timer/file cleanup on failure or timeout in renderHtmlToPdfBuffer, and hoist the store currency lookup out of the per-bill loop in getOrdersWithItemsForBills, with thorough behavioral unit test coverage.
Testing
Executed targeted test suites (
tests/printer-ipc.test.ts,tests/daily-invoices-export.test.ts, andtests/reports-export.test.tsincluding its real ElectronprintToPDFchild run) and drove all 6 scenarios live in a real Electron runtime against an isolated SQLite database and real ChromiumBrowserWindowinstances, capturing the generated compiled invoices HTML/PDF and structured verification results in the evidence directory; all checks passed.npx tsx tests/printer-ipc.test.tsrender-process-gone),renderHtmlToPdfBufferrejects immediately with the termination reason and cleans up the hidden BrowserWindow,…npx tsx tests/printer-ipc.test.tsclosedevent),renderHtmlToPdfBufferrejects immediately and cleans up the staging HTML file, timers, and listenersnpx tsx tests/printer-ipc.test.tspdfWindow.loadFile()fails to load the document, the rejection propagates directly without registering a redundantdid-fail-loadlistener, and cleans up the hidden BrowserWindow, staging HTML…npx tsx tests/printer-ipc.test.tsgetOrdersWithItemsForBillshoists the tenant currency minor-unit factor lookup outside the per-bill loop so SQLitesettingsis queried once per call rather th…npx tsx tests/printer-ipc.test.tsand `npx tsx tests/daily-invoic…Evidence: Live Electron verification results JSON
{ "scenario6_currencyHoist": { "billCount": 6, "projectedOrdersCount": 6, "settingsQueryCount": 2, "settingsQueries": [ "SELECT value FROM settings WHERE key = ?", "SELECT value FROM settings WHERE key = ?" ] }, "scenario1_saveDialogExcluded": { "defaultTimeoutMs": 30000, "configuredRenderTimeoutMs": 2500, "simulatedSaveDialogDelayMs": 3000, "totalElapsedMs": 3864, "saveResult": { "success": true, "path": "~/.no-mistakes/evidence/01M6YFKNJNAQ24EK0STXX2TQM7/live-exported-invoices.pdf" }, "pdfBytes": 259200, "pdfHeader": "%PDF-1.4", "windowDestroyed": true, "stagingFileDeleted": true }, "scenario2_renderTimeout": { "ipcResult": { "success": false, "error": "PDF rendering timed out after 800ms" }, "windowDestroyed": true, "destroyCalledOnTimeout": true, "stagingFileDeleted": true, "outputPdfCreated": false, "userClosedListenersRemaining": 0 }, "scenario3_rendererCrash": { "error": "PDF renderer process terminated unexpectedly (killed)", "windowDestroyed": true, "stagingFileDeleted": true, "userClosedListenersRemaining": 0 }, "scenario4_windowClosed": { "error": "PDF rendering window closed unexpectedly", "windowDestroyed": true, "stagingFileDeleted": true, "userClosedListenersRemaining": 0 }, "scenario5_loadFileFailure": { "error": "ERR_BLOCKED_BY_CLIENT (-20) loading 'file:///var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-live-verify-weB7KO/non-existent-file-404.html'", "windowDestroyed": true, "stagingFileDeleted": true, "userClosedListenersRemaining": 0, "didFailLoadListenersRegistered": 0 } }Evidence: Live compiled daily invoices PDF exported via Electron printToPDF
Evidence: Live compiled daily invoices HTML input document
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
🔧 **Test** - 1 issue found → no changes applied ✅
🔧 No changes applied.
✅ Re-checked - no issues remain.
npx tsx tests/printer-ipc.test.tsrender-process-gone),renderHtmlToPdfBufferrejects immediately with the termination reason and cleans up the hidden BrowserWindow,…npx tsx tests/printer-ipc.test.tsclosedevent),renderHtmlToPdfBufferrejects immediately and cleans up the staging HTML file, timers, and listenersnpx tsx tests/printer-ipc.test.tspdfWindow.loadFile()fails to load the document, the rejection propagates directly without registering a redundantdid-fail-loadlistener, and cleans up the hidden BrowserWindow, staging HTML…npx tsx tests/printer-ipc.test.tsgetOrdersWithItemsForBillshoists the tenant currency minor-unit factor lookup outside the per-bill loop so SQLitesettingsis queried once per call rather th…npx tsx tests/printer-ipc.test.tsand `npx tsx tests/daily-invoic…npx tsx tests/printer-ipc.test.tsnpx tsx tests/daily-invoices-export.test.tsnpx tsx tests/reports-export.test.ts./node_modules/.bin/electron --no-sandboxlive verification drivingsave-html-as-pdfIPC,renderHtmlToPdfBufferfailure modes (forcefullyCrashRenderer,window.close, stalledprintToPDF, failedloadFile), andgetOrdersWithItemsForBillsSQLite query count across 6 bills✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.