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

Throw a more helpful error if Buffer is undefined in decoder #93

Merged
merged 1 commit into from Jul 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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