imagemin / meta

General discussion repo for imagemin related projects
6 stars 2 forks source link

Include image file name to the error message #8

Closed shinnn closed 9 years ago

shinnn commented 9 years ago

I want to check which image file is corrupt when optimization fails.

kevva commented 9 years ago

In which module? imagemin?

shinnn commented 9 years ago

Plugins.

For example, imagemin-webp outputs the error like this:

Error: Command failed: Corrupt JPEG data: 26 extraneous bytes before marker 0xc2
Quantization table 0x00 was not defined
Error! Could not process file /var/folders/2n/y4hbl_pd05l41w9rh15mm4700000gn/T/8b39daba-b14c-4c0a-b74e-5f12538e7d54
Error! Cannot read input picture file '/var/folders/2n/y4hbl_pd05l41w9rh15mm4700000gn/T/8b39daba-b14c-4c0a-b74e-5f12538e7d54'

And imagemin-jpeg-recompress does:

Error: Corrupt JPEG data: 26 extraneous bytes before marker 0xc2
Quantization table 0x00 was not defined
shinnn commented 9 years ago

I think it's better to set fileName property of the error, like gulp plugins do.

https://github.com/sindresorhus/gulp-esnext/blob/7a9bca02dc56b90139edc379b19f29b9d97f5b41/index.js#L40

shinnn commented 9 years ago

Example implementation:

exec.run(file.contents, function (err, buf) {
  if (err) {
    err.fileName = err.fileName || file.path; // set fileName property if it's not specified
    cb(err);
    return;
  }
  file.contents = buf;
  cb(null, file);
});
kevva commented 9 years ago

@shinnn, we should do this.

shinnn commented 9 years ago

@kevva I'll update plugins.

kevva commented 9 years ago

This should be fixed now.

shinnn commented 9 years ago

Thanks, @kevva.