Intermittent in 2.10: "Error while executing pdf-utils operations" (root.$pdf.pages[i].items seems to be undefined)
-
I'm evaluating 2.10 (official jsreport Docker image).
I get the below error out of the blue on some renders.I have managed to stress jsreport in my dev environment and discovered that this error comes up about every 10:th render. Sometimes after 5 renders and sometimes after 20.
It happens both in "in-process" and in "dedicated-process".
Here is the pdfUtils config for this particular report. I haven't tried any other reports with 2.10.
I went back to 2.7.1 (this is what I'm using in production). After 25 renders of this report I couldn't provoke the error. I also log every error in production, and I haven't seen this. I'm pretty sure this is related to either 2.8 or 2.10.
Error: Error while executing pdf-utils operations. Error while executing templating engine. Cannot read property 'find' of null. Error on line 180:47. 178 | console.log('Page count ' +root.$pdf.pages.length); 179 | for (let i = 0; i < root.$pdf.pages.length; i++) { > 180 | const item = root.$pdf.pages[i].items.find(item => item.id === id) | ^ 181 | if (item) { 182 | return i + 1 ; //add one more page to account for the cover page 183 | } at module.exports (/app/node_modules/jsreport-core/lib/util/createError.js:11:13) at Reporter.createError (/app/node_modules/jsreport-core/lib/reporter.js:332:12) at AsyncFunction.<anonymous> (/app/node_modules/jsreport-pdf-utils/lib/main.js:382:22) at runMicrotasks (<anonymous>) at processTicksAndRejections (internal/process/task_queues.js:97:5) caused by: TypeError: Cannot read property 'find' of null at Object.getPage (evaluate-template-engine-helpers.js:180:47) at Object.<anonymous> (/app/node_modules/jsreport-core/lib/render/engineScript.js:207:27) at Object.wrapper (/app/node_modules/handlebars/dist/cjs/handlebars/internal/wrapHelper.js:15:19) at eval (eval at createFunctionContext (/app/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:1:1), <anonymous>:18:104) at prog (/app/node_modules/handlebars/dist/cjs/handlebars/runtime.js:268:12) at execIteration (/app/node_modules/handlebars/dist/cjs/handlebars/helpers/each.js:51:19) at Object.<anonymous> (/app/node_modules/handlebars/dist/cjs/handlebars/helpers/each.js:61:13) at Object.wrapper (/app/node_modules/handlebars/dist/cjs/handlebars/internal/wrapHelper.js:15:19) at eval (eval at createFunctionContext (/app/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:1:1), <anonymous>:8:52) at prog (/app/node_modules/handlebars/dist/cjs/handlebars/runtime.js:268:12)
-
Could you to email me the export zip so I can try to replicate it? Thank you
-
Jan, I have emailed you. Here is my jsreport.config, if you need it:
{ "logger": { "console": {"transport": "console", "level": "silly"} }, "reportTimeout": 600000, "httpPort": 5488, "allowLocalFilesAccess": true, "store": { "provider": "fs" }, "blobStorage": { "provider": "fs" }, "templatingEngines": { "numberOfWorkers": 4, "strategy": "in-process" }, "extensions": { "chrome-pdf": { "strategy": "chrome-pool", "numberOfWorkers": 4 }, "express": { "inputRequestLimit": "50mb" }, "child-templates": { "parallelLimit": 4 }, "fs-store": { "sync": { "usePolling": false } } } }
-
Oh, I forgot to mention, the code with the error is in the "toc" child template. But I don't think the code is very relevant. The intermittent nature of the problem seems to indicate that it comes from below in the call chain.
-
So finally, I found the problem. Here is some technical background if interested in what is changed in the 2.10.0.
https://github.com/jsreport/jsreport/issues/725What's happening here is that we aren't able to properly parse the hidden marks you add to the pdf using
pdfAddPageItem
helper.
For some reason, the mozila pdfjs skips lettersf
andi
when rendered using your fonts.
The current solution is to add an explicit font to our hidden marks. This is fortunately very easy. Just add this to your main template styles..jsreport-pdf-utils-page-item { font-family: Helvetica } .jsreport-pdf-utils-page-group { font-family: Helvetica }
I tried to render several hundred of reports with 10x in parallel and didn't see the error occurring again.
Please try it out and let me know.
We will then consider to always use the explicit font family.
-
Great bug catch! I can imagine some hair-scratching went into this hunt.
I don't quite follow why i and f would be skipped. But I'll happily change font and call it a day.
I think I'm ready to put 2.10 into production now.
-
Hi again.
Most of my reports share a global CSS, but sometimes I don't use it. In those cases I have to remember to add the page-item and page-group classes, which I will most certainly miss sometime in the future.Would it be possible for you to prepend every report with those classes by default in the next jsreport release?
-
We will add the explicit font-family the most likely in the next release.