pdf2json icon indicating copy to clipboard operation
pdf2json copied to clipboard

Error thrown that is not handled or returned

Open snowhunter opened this issue 6 years ago • 0 comments

I have a service that a 3rd party is sending me PDFs, which sometimes are invalid. I would like to reject them gracefully, providing some sort of feedback, but the error isn't being returned via the pdfParser_dataError emitter, instead pdf2json appears to exit taking down my application. I've narrowed it down to having a Bad Xref entry, and obj.js:1053 where it errors but doesn't seem to be handled gracefully. Tracking the code, it seems like the util.error is not being made available to the other libraries.

My particular error originates in obj.js:getEntry at:

    var obj1 = parser.getObj();
        var obj2 = parser.getObj();
        var obj3 = parser.getObj();
        if (!isInt(obj1) || obj1 !== num ||
            !isInt(obj2) || obj2 !== gen ||
            !isCmd(obj3)) {
          error('bad XRef entry');
        }

If I add a console.log("Error is: " + typeof error); in there, I do get the printout of

Error is: undefined Debugger attached. Waiting for the debugger to disconnect...

Process finished with exit code 0

Before it bombs out with the attempt to call error().

snowhunter avatar Mar 21 '18 09:03 snowhunter