Skip to content

Commit b58cc11

Browse files
authored
fix(decoder): rethrow a more helpful error if Buffer is undefined (#93)
1 parent 2c90858 commit b58cc11

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lib/decoder.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,13 +1123,19 @@ function decode(jpegData, userOpts = {}) {
11231123
if(decoder.comments.length > 0) {
11241124
image["comments"] = decoder.comments;
11251125
}
1126-
} catch (err){
1127-
if (err instanceof RangeError){
1126+
} catch (err) {
1127+
if (err instanceof RangeError) {
11281128
throw new Error("Could not allocate enough memory for the image. " +
11291129
"Required: " + bytesNeeded);
1130-
} else {
1131-
throw err;
1130+
}
1131+
1132+
if (err instanceof ReferenceError) {
1133+
if (err.message === "Buffer is not defined") {
1134+
throw new Error("Buffer is not globally defined in this environment. " +
1135+
"Consider setting useTArray to true");
1136+
}
11321137
}
1138+
throw err;
11331139
}
11341140

11351141
decoder.copyToImageData(image, opts.formatAsRGBA);

0 commit comments

Comments
 (0)