posthtml / posthtml-img-autosize

Auto setting the width and height of <img>
MIT License
28 stars 8 forks source link

Cannot handle error from image-size package #16

Closed Grawl closed 4 years ago

Grawl commented 4 years ago

My script looks like this:

try {
    const body = await posthtml()
        .use(require('posthtml-img-autosize')({
            processEmptySize: true,
        }))
        .process(html)
        .then(result => result.html)
        .catch(error => {
            console.log({ error })
        })
    return body
} catch (error) {
    console.log(error)
}

I have try/catch here and .catch in promise, what I am doing wrong?

But I have TypeError: unsupported file type: undefined (file: undefined) on one of my pages.

This image causes this error:

1400593094_shiny

maltsev commented 4 years ago

The second undefined in that error message is the image file path:

// node_modules/image-size/lib/index.js
throw new TypeError('unsupported file type: ' + type + ' (file: ' + filepath + ')');

So I assume that the lib just couldn't find the image.

I also checked, your code works on my machine. I'm closing this ticket since it doesn't seem like a bug in posthtml-img-autosize. Feel free to re-open if needed.

Grawl commented 4 years ago

its broken image. I fix it using imgproxy