webpack-contrib/image-minimizer-webpack-plugin

Include filename in squoosh error report

mjpieters opened this issue · 4 comments

  • Operating System: MacOS
  • Node Version: 16
  • NPM Version: 7
  • webpack Version: 5
  • image-minimizer-webpack-plugin Version: checkout from git, revision 3a38d92

Expected Behavior / Situation

There is an image in my project that is not being accepted by libsquoosh. When running webpack, I'd like image-minimizer-webpack-plugin to tell me what image that is so I can troubleshoot the situation.

Actual Behavior / Situation

The output is less than helpful:

ERROR in Binary blob has an unsupported format

Modification Proposal

Please include the filename in the error output; I modified the error handler in utils/squooshMinify.js:

} catch (error) {
if (imagePool) {
await imagePool.close();
}
result.errors.push(error);
return result;
}

to prepend the error message with the filename:

  } catch (error) {
    if (imagePool) {
      await imagePool.close();
    }

    result.errors.push(`${filename}: ${error}`);
    return result;
  }

This makes the output much more useful:

ERROR in img/favicon.png: Binary blob has an unsupported format

While I don't yet know why libsquoosh is unhappy about the file, at least I can now exclude it from being processed.

I also figured out why the image caused problems: the plugin passes in the whole buffer, which contains more than just the image file.

See this Stack Overflow answer for why this is a bad idea; libsquoosh takes the whole underlying buffer and so won't always be able to detect the image type.

I fixed it locally by passing in the correct portion of the underlying ArrayBuffer:

    image = imagePool.ingestImage(input.buffer.slice(input.byteOffset, input.byteOffset + input.byteLength));

Perhaps this is a bug in libsquoosh, perhaps this is better fixed in the plugin, I'm not that versed in Node / Javascript development.

I've filed GoogleChromeLabs/squoosh#1095, lets see what the squoosh team thinks.

Fixed by #278, regarding to the problem with buffer, let's wait answer from squoosh, we use their standard API and example from docs, sorry for delay with fix, I was very busy and have a lot of tasks 😞 Feel free to open an issue regarding when squoosh give an answer, sorry again

let's wait answer from squoosh

One of the project maintainers has acknowledged it is a bug on their side now.