Skip to content

Commit

Permalink
fix unhandled promise rejection asBuffer() take 2
Browse files Browse the repository at this point in the history
Refs #312
  • Loading branch information
rkusa committed Jul 24, 2023
1 parent cec60e6 commit c3af05f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [2.5.2]
### Fixed
- Fixed unhandled promise rejection in `doc.asBuffer()` - take two

## [2.5.1]
### Fixed
- Fixed unhandled promise rejection in `doc.asBuffer()`
Expand Down
2 changes: 1 addition & 1 deletion lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ class Document extends Readable {
this.on("end", () => resolve(Buffer.concat(chunks)));
this.on("error", reject);
if (shouldEnd) {
return this.end();
this.end().catch(reject);
}
});
if (typeof callback === "function") {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "pdfjs",
"author": "Markus Ast <[email protected]>",
"version": "2.5.1",
"version": "2.5.2",
"description": "A Portable Document Format (PDF) generation library targeting both the server- and client-side.",
"keywords": [
"pdf",
Expand Down
19 changes: 19 additions & 0 deletions test/others/asBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,22 @@ test("asBuffer", function (t) {
})
.catch(t.error);
});

test("error in pending queue", async function (t) {
t.plan(1);

let doc = new pdf.Document({
font: f.font.afm.regular,
});

doc._pending.push(() => {
return new Promise(() => {
throw new Error("Test Error");
});
});

await doc
.asBuffer()
.then(() => t.fail("asBuffer expected to reject"))
.catch(() => t.pass("as Buffer rejected"));
});

0 comments on commit c3af05f

Please sign in to comment.