Prevent docxChart errors to fail the complete render?



  • Hi,

    I'm experimenting with the docx recipe, and when using docxChart, I noticed the slightest error in the data (missing data, incorrect data structure) fails the complete render with an error like:

    2020-10-19T14:29:39.111Z - warn: Error when processing render request 12 Error while executing templating engine. docxChart helper requires data parameter to be set. Error on line 312:13.
    
      310 |   global.docxChart = function (options) {
      311 |     if (options.hash.data == null) {
    > 312 |       throw new Error('docxChart helper requires data parameter to be set')
          |             ^
      313 |     }
      314 |
      315 |     if (!Array.isArray(options.hash.data.labels) || options.hash.data.labels.length === 0) {
    
     Error: docxChart helper requires data parameter to be set
        at Object.global.docxChart (evaluate-template-engine-helpers.js:312:13)
        at Object.<anonymous> (/home/patrick/test/node_modules/jsreport-core/lib/render/engineScript.js:207:27)
        at Object.wrapper (/home/patrick/test/node_modules/handlebars/dist/cjs/handlebars/internal/wrapHelper.js:15:19)
        at eval (eval at createFunctionContext (/home/patrick/test/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:262:23), <anonymous>:13:128)
    

    or

    2020-10-19T13:52:04.386Z - warn: Error when processing render request 15 Error while executing docx recipe. Cannot read property 'cloneNode' of undefined Error: Error while executing docx recipe. Cannot read property 'cloneNode' of undefined
        at module.exports (/home/patrick/test/node_modules/jsreport-core/lib/util/createError.js:11:13)
        at Reporter.createError (/home/patrick/test/node_modules/jsreport-core/lib/reporter.js:332:12)
        at Object.execute (/home/patrick/test/node_modules/jsreport-docx/lib/recipe.js:58:20)
        at runMicrotasks (<anonymous>)
        at processTicksAndRejections (internal/process/task_queues.js:93:5)
        at async module.exports (/home/patrick/test/node_modules/jsreport-core/lib/render/render.js:150:5)
    caused by: TypeError: Cannot read property 'cloneNode' of undefined
        at /home/patrick/test/node_modules/jsreport-docx/lib/postprocess/processChart.js:370:75
        at Array.map (<anonymous>)
        at processChart (/home/patrick/test/node_modules/jsreport-docx/lib/postprocess/processChart.js:369:64)
        at /home/patrick/test/node_modules/jsreport-docx/lib/postprocess/drawingObject.js:71:33
        at processTicksAndRejections (internal/process/task_queues.js:93:5)
    

    Would it be possible to still log these errors as warnings but not fail the complete render?


  • administrators

    hi! preventing the render to fail it is questionable, when we hit an error during the docx generation it means that we are going to enter into an inconsistent state, or a case that which we did not consider previously, which means that the final docx will be an invalid file or even worse it won't produce any file. though i agree that maybe throwing when the data parameter is null probably is too much, maybe we can instead just left the chart as it is. why do you want to have this just as warnings? the recipe failing to produce the docx should always end in error, however, there can be some cases (like the empty data to chart) that maybe can be just warnings, but this needs to be evaluated per each case, if you have other cases that you think that are better as warnings let us know, and we can evaluate it



  • Hi, and thanks for the prompt response!

    Agreed leaving the docx output in an inconsistent state is not desired at all.

    My goal is to try and speed up the time needed to develop a template making many changes at once. Failing on the first error makes it a painful retry and error cycle.

    Having some cases like the empty data to chart just warnings would be a great improvement for starters.

    I only glanced at the jsreport-docx code, so I do not realize yet if this is possible, but couldn't the output be buffered by logical blocks, e.g. when processing a docxChart or a docxTable, before making it in the output when the complete block was properly processed?


  • administrators

    hi! thanks for the feedback, we intentionally make the implementation to work this way because it is easier to maintain and keep it easier to reason about. parsing and manipulation docx is not so easy so we prefer to fail early than optimize for show warnings, I understand that this may block you from being fast while doing changes to your docx template, however maybe you can try this https://jsreport.net/learn/docx#development, with this enabled you should be able to edit docx, and have studio reload and re-run the template automatically, so a few step less to do during development.



  • I'm already using Studio configured to detect filesystem changes, but I'm editing the template document in Word Online as I cannot use Word directly on linux and editing with Libreoffice causes formatting issues. So, I'm downloading a copy once in a while. Poor workflow, I agree...

    An odt recipe would be awesome!


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.