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

Minified PDFJS worker unable to properly serialize exceptions #12209

Closed
gordoncl opened this issue Aug 13, 2020 · 0 comments · Fixed by #12210
Closed

Minified PDFJS worker unable to properly serialize exceptions #12209

gordoncl opened this issue Aug 13, 2020 · 0 comments · Fixed by #12210
Labels

Comments

@gordoncl
Copy link

I primarily use pdfjs-dist and have up until recently loaded the minified worker.

When upgrading from version 2.1.266 to version 2.4.456, I noticed that the errors thrown from getDocument were undefined in the event of a bad URL, where they used to come in as MissingPDFException, for example. I suspect the problem is also present on 2.5.207 and was introduced in 2.3.200.

I believe the source of the problem is due to the fact that reflection is now being used by BaseException and the code I'm using is minified, so the names of the classes are being changed. The problem was likely introduced in this commit with this line of code:

5d93fda#diff-8d2b578d58d4d8c8a2975020fbbc84d9R410

This causes problems when trying to deserialize the exception when passed from the worker as this switch statement results in undefined:

pdf.js/src/display/api.js

Lines 2255 to 2281 in 1a6816b

messageHandler.on("DocException", function (ex) {
let reason;
switch (ex.name) {
case "PasswordException":
reason = new PasswordException(ex.message, ex.code);
break;
case "InvalidPDFException":
reason = new InvalidPDFException(ex.message);
break;
case "MissingPDFException":
reason = new MissingPDFException(ex.message);
break;
case "UnexpectedResponseException":
reason = new UnexpectedResponseException(ex.message, ex.status);
break;
case "UnknownErrorException":
reason = new UnknownErrorException(ex.message, ex.details);
break;
}
if (
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || TESTING")
) {
assert(reason instanceof Error, "DocException: expected an Error.");
}
loadingTask._capability.reject(reason);
});

In the case of the minified file one can see that ex will come through as an object that looks like:

{ 
  message: "Failed to fetch",
  name: "e",
  details: "TypeError: Failed to fetch"
}

Which does not match the string values in the switch, which will never be minified themselves because they are string literals.

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

Successfully merging a pull request may close this issue.

2 participants