Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled rejections #3417

Closed
mitar opened this issue Jun 30, 2013 · 11 comments · Fixed by #4945
Closed

Unhandled rejections #3417

mitar opened this issue Jun 30, 2013 · 11 comments · Fixed by #4945

Comments

@mitar
Copy link
Contributor

mitar commented Jun 30, 2013

I am using pdf.js in node.js. It works pretty well, but the issue is that pdf.js does not seem to pass errors from the worker to the main promises (getDocument, getPage, getTextContent, render) in the case of error. For example, the last page of this PDF cannot be rendered with pdf.js currently and I get this error printed:

Error: Unknown compression method in flate stream: 89, 135
    at error (.../.npm/node_modules/pdf.js/src/util.js:64:7)
    at Object.FlateStream (.../.npm/node_modules/pdf.js/src/stream.js:381:7)
    at Object.Parser_makeFilter [as makeFilter] (.../.npm/node_modules/pdf.js/src/parser.js:300:16)
    at Object.Parser_filter [as filter] (.../.npm/node_modules/pdf.js/src/parser.js:273:21)
    at Object.Parser_makeStream [as makeStream] (.../.npm/node_modules/pdf.js/src/parser.js:265:21)
    at Object.Parser_getObj [as getObj] (.../.npm/node_modules/pdf.js/src/parser.js:107:18)
    at Object.XRef_fetch [as fetch] (.../.npm/node_modules/pdf.js/src/obj.js:961:22)
    at Object.XRef_fetchIfRef [as fetchIfRef] (.../.npm/node_modules/pdf.js/src/obj.js:907:19)
    at Object.Dict_get [as get] (.../.npm/node_modules/pdf.js/src/obj.js:80:28)

And then after this:

Warning: Unhandled rejection: Error: Unknown compression method in flate stream: 89, 135

This is all very nice debugging output, but the issue is that all promises I am waiting on (getDocument, getPage, getTextContent, render) are left unresolved. Is there a way that this errors could be passed back to those promises so that at least one would be rejected?

@timvandermeij
Copy link
Contributor

Yury probably knows more about this. I find it really strange that only the last page is not rendered and the rest is rendered perfectly...

/cc @yurydelendik

@mitar
Copy link
Contributor Author

mitar commented Aug 2, 2013

This is because only the last page contains embedded JPG image (or something) which has unknown compression.

@timvandermeij
Copy link
Contributor

It seems like the last page is either corrupted, or a really unknown compression is used, since Adobe Acrobat also complains when I open it and go to the last page: "Insufficient data for an image" (translated from Dutch) is the error I'm getting.

Edit: http://blogs.adobe.com/dmcmahon/2012/08/21/acrobat-insufficient-data-for-an-image-error-after-updating-to-10-1-4-or-9-5-2 states a possible reason for this, which might help the developers: "This error occurs due to a problem in the Adobe Acrobat/Reader functionality used to display scanned documents and/or documents containing JP2K images."

@mitar
Copy link
Contributor Author

mitar commented Aug 2, 2013

Yes. But the issue is that promise is not rejected! This is the problem. I know that there are definitely bad PDFs in the world which are impossible to parse correctly. But we should get an error.

@timvandermeij
Copy link
Contributor

@mitar Indeed. I was just trying to find out what caused the error :) I don't know why the promise is not rejected.

@yurydelendik
Copy link
Contributor

@marcosps
Copy link

marcosps commented Aug 5, 2013

Web console:

[07:22:40.742] "PDF e13db2ba590fba92626889ee71ad58 [1.4 pdfTeX-1.40.4 /
LaTeX with hyperref package](PDF.js: 0.8.396)"
[07:22:54.047] "Warning: Unhandled rejection: Error: Unknown compression
method in flate stream: 89, 135"

Em 08/04/2013 07:06 PM, Yury Delendik escreveu:

http://arxiv.org/pdf/0704.0739v2.pdf


Reply to this email directly or view it on GitHub
#3417 (comment).

@mitar
Copy link
Contributor Author

mitar commented Aug 23, 2013

This is even written in the comment here.

@mitar
Copy link
Contributor Author

mitar commented Aug 26, 2013

It seems backtrace() in utils.js does not print the whole stack. I added to error() my own log(new Error().stack) and I got additional last line:

at Object.PartialEvaluator_getTextContent [as getTextContent] (.../.npm/node_modules/pdf.js/src/evaluator.js:938:32)

@mitar
Copy link
Contributor Author

mitar commented Sep 1, 2013

@awwx commented:

A library that uses promises should use a promise-based version of setTimeout, such as https://github.com/cujojs/when/blob/master/docs/api.md#whendelay

From the example in the API docs:

// Do something after 1 second, similar to using setTimeout
delay(1000).then(doSomething);

Because the doSomething callback is called from then, a thrown exception will be caught and correctly cause the promise to be rejected.

@CodingFabian
Copy link
Contributor

@mitar still interested in this issue? @Snuffleupagus made a PR #4945 you might want to check out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants