Callback result safety
Closed this issue · 3 comments
expwez commented
Please, add some kind of a check for callback result, because I just miss to call return in my callback and it gave me an error kind of:
(node:16) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'getBufferAsync' of undefined
at jimp__default.default.read.then.then.img (/srv/app/node_modules/gulp-jimp-wrapper/dist/index.js:35:24)
at <anonymous>
The first thing I thought about it was that there is something wrong with the package, but, fortunately, there was not. After a little debugging I found out the reason was my own inaccuracy. It's not fatal, but I just would appreciate it if you add some checks and a more understandable exception for that.
Thank you for your time in advance.
exuanbo commented
Yes you're right, it's better to have some meaningful error messages.
I'll work on it.
exuanbo commented
Try the new version. 🤓
const processImage = async (img, cb, MIMEType) => {
const res = await jimp.read(img.contents).then(cb)
if (!(res instanceof jimp)) {
throw new Error(
'Jimp instance must be returned from the callback argument.'
)
}
return res.getBufferAsync(MIMEType)
}
expwez commented
Works for me. Thank you