diff --git a/docs/src/content/docs/changelog/v0.34.5.md b/docs/src/content/docs/changelog/v0.34.5.md index a754c33a..886932b8 100644 --- a/docs/src/content/docs/changelog/v0.34.5.md +++ b/docs/src/content/docs/changelog/v0.34.5.md @@ -9,3 +9,6 @@ slug: changelog/v0.34.5 * Add support for BigTIFF output. [#4459](https://github.com/lovell/sharp/pull/4459) [@throwbi](https://github.com/throwbi) + +* Improve error messaging when only warnings issued. + [#4465](https://github.com/lovell/sharp/issues/4465) diff --git a/src/pipeline.cc b/src/pipeline.cc index 2b952fc9..4a848293 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -1278,7 +1278,12 @@ class PipelineWorker : public Napi::AsyncWorker { if (what && what[0]) { (baton->err).append(what); } else { - (baton->err).append("Unknown error"); + if (baton->input->failOn == VIPS_FAIL_ON_WARNING) { + (baton->err).append("Warning treated as error due to failOn setting"); + baton->errUseWarning = true; + } else { + (baton->err).append("Unknown error"); + } } } // Clean up libvips' per-request data and threads @@ -1293,7 +1298,11 @@ class PipelineWorker : public Napi::AsyncWorker { // Handle warnings std::string warning = sharp::VipsWarningPop(); while (!warning.empty()) { - debuglog.Call(Receiver().Value(), { Napi::String::New(env, warning) }); + if (baton->errUseWarning) { + (baton->err).append("\n").append(warning); + } else { + debuglog.Call(Receiver().Value(), { Napi::String::New(env, warning) }); + } warning = sharp::VipsWarningPop(); } diff --git a/src/pipeline.h b/src/pipeline.h index eaec71fa..14ee5456 100644 --- a/src/pipeline.h +++ b/src/pipeline.h @@ -198,6 +198,7 @@ struct PipelineBaton { bool jxlLossless; VipsBandFormat rawDepth; std::string err; + bool errUseWarning; int keepMetadata; int withMetadataOrientation; double withMetadataDensity; @@ -373,6 +374,7 @@ struct PipelineBaton { jxlEffort(7), jxlLossless(false), rawDepth(VIPS_FORMAT_UCHAR), + errUseWarning(false), keepMetadata(0), withMetadataOrientation(-1), withMetadataDensity(0.0), diff --git a/test/fixtures/bonne.geo.tif b/test/fixtures/bonne.geo.tif new file mode 100644 index 00000000..1592bf86 Binary files /dev/null and b/test/fixtures/bonne.geo.tif differ diff --git a/test/fixtures/index.js b/test/fixtures/index.js index 153eb37b..b5714875 100644 --- a/test/fixtures/index.js +++ b/test/fixtures/index.js @@ -113,6 +113,7 @@ module.exports = { inputTiff8BitDepth: getPath('8bit_depth.tiff'), inputTifftagPhotoshop: getPath('tifftag-photoshop.tiff'), // https://github.com/lovell/sharp/issues/1600 inputTiffFogra: getPath('fogra-0-100-100-0.tif'), // https://github.com/lovell/sharp/issues/4045 + inputTiffGeo: getPath('bonne.geo.tif'), // https://download.osgeo.org/geotiff/samples/intergraph inputJp2: getPath('relax.jp2'), // https://www.fnordware.com/j2k/relax.jp2 inputJp2TileParts: getPath('relax_tileparts.jp2'), // kdu_expand -i relax.jp2 -o relax-tmp.tif ; kdu_compress -i relax-tmp.tif -o relax_tileparts.jp2 -jp2_space sRGB Clayers=8 -rate 1.0,0.04 Stiles='{128,128}' ORGtparts=L ; rm relax-tmp.tif diff --git a/test/unit/failOn.js b/test/unit/failOn.js index 3e0dbabf..9add6778 100644 --- a/test/unit/failOn.js +++ b/test/unit/failOn.js @@ -103,4 +103,11 @@ describe('failOn', () => { fs.createReadStream(fixtures.inputJpgTruncated).pipe(writable); return writable.toBuffer(); }); + + it('converts warnings to error for GeoTIFF', async () => { + await assert.rejects( + sharp(fixtures.inputTiffGeo).toBuffer(), + /Unknown field with tag 33550/ + ); + }); });