I was hashing some images in a loop using promises and a broken image caused the entire program to crash instead of being caught by the promise chain.
/node_modules/@cwasm/nsgif/index.js:38
throw new Error('Failed to decode gif image')
^
Error: Failed to decode gif image
at Object.exports.decode (/node_modules/@cwasm/nsgif/index.js:38:11)
at decodeImage (/node_modules/@canvas/image/index.js:28:16)
at imageFromBuffer (/node_modules/@canvas/image/index.js:185:29)
at /node_modules/imghash/index.js:22:15
at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:61:3)
I managed to recreate the issue by making a test file with content GIF89a to simulate a malformed GIF and running the following code, which results in the same error. Instead of ignoring the error, it still crashes.
I did a little digging, and it seems to be occuring because imageFromBuffer is not a true promise in that it returns the promise after doing some synchronous work (which returns the error above). I managed to get it to work properly by amending the code in index.js to this, but it's not really a nice fix (and probably needs to be added to the if statement above fs.readFile):
I was hashing some images in a loop using promises and a broken image caused the entire program to crash instead of being caught by the promise chain.
I managed to recreate the issue by making a test file with content
GIF89a
to simulate a malformed GIF and running the following code, which results in the same error. Instead of ignoring the error, it still crashes.I did a little digging, and it seems to be occuring because
imageFromBuffer
is not a true promise in that it returns the promise after doing some synchronous work (which returns the error above). I managed to get it to work properly by amending the code in index.js to this, but it's not really a nice fix (and probably needs to be added to the if statement abovefs.readFile
):