Skip to content

Commit

Permalink
fix(decoder): rethrow a more helpful error if Buffer is undefined (jp…
Browse files Browse the repository at this point in the history
  • Loading branch information
DT-1236 committed Jul 15, 2021
1 parent b3d958d commit 51113b4
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/decoder.js
Expand Up @@ -1123,13 +1123,19 @@ function decode(jpegData, userOpts = {}) {
if(decoder.comments.length > 0) {
image["comments"] = decoder.comments;
}
} catch (err){
if (err instanceof RangeError){
} catch (err) {
if (err instanceof RangeError) {
throw new Error("Could not allocate enough memory for the image. " +
"Required: " + bytesNeeded);
} else {
throw err;
}

if (err instanceof ReferenceError) {
if (err.message === "Buffer is not defined") {
throw new Error("Buffer is not globally defined in this environment. " +
"Consider setting useTArray to true");
}
}
throw err;
}

decoder.copyToImageData(image, opts.formatAsRGBA);
Expand Down

0 comments on commit 51113b4

Please sign in to comment.