diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a8f520b..6969764f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +### [1.0.2] + + - Upgrade ImageMagick to the latest 7.1.1-27 (git) + - Fix [#72](https://github.com/mmomtchev/magickwand.js/issues/72), exception in constructors used for implicit casting are not catchable + ### [1.0.1] 2024-01-18 - Update ImageMagick to 7.1.1-26 diff --git a/deps/ImageMagick b/deps/ImageMagick index 83eefaf2..aa4afc5f 160000 --- a/deps/ImageMagick +++ b/deps/ImageMagick @@ -1 +1 @@ -Subproject commit 83eefaf2aab871d4e12e7f70901d9785b4f0ea01 +Subproject commit aa4afc5f21f1e90c0ad63897ca7afbd7fa43b93e diff --git a/src/ImplicitCasting.i b/src/ImplicitCasting.i index bf2860de..8f8ed076 100644 --- a/src/ImplicitCasting.i +++ b/src/ImplicitCasting.i @@ -18,10 +18,21 @@ { // We apply the default std::string typemap - it parses // its argument in a local temporary $1 - std::string *$1; + std::string *$1 = nullptr; $typemap(in, const std::string &); // Construct the object from this string - from_string_temp = $*ltype(*$1); + try { + // SWIG will automatically insert an exception handler in actions + // but this does not apply to typemaps - here we call ImageMagick code + // which can throw + from_string_temp = $*ltype(*$1); + } catch (const Magick::Exception &e) { + delete $1; + // SWIG_Raise is the language-independent macro which expands to + // the language-specific function call, it is available only in .i files + SWIG_NAPI_Raise(env, e.what()); + SWIG_fail; + } // The string is not needed anymore delete $1; } diff --git a/test/Color.shared.ts b/test/Color.shared.ts index e03574e1..d8f04310 100644 --- a/test/Color.shared.ts +++ b/test/Color.shared.ts @@ -76,6 +76,12 @@ export default function ( .map((v) => Math.floor(v * 255).toString(16).padStart(2, '0')).join(''), '#ff7f0160'); }); + + it('handling invalid color', () => { + assert.throws(() => { + new Color('invalid'); + }, /unrecognized color `invalid'/); + }); }); }); } diff --git a/test/Image.shared.ts b/test/Image.shared.ts index 9d7cff35..b9b8968b 100644 --- a/test/Image.shared.ts +++ b/test/Image.shared.ts @@ -45,6 +45,12 @@ export default function ( // @ts-ignore assert.throws(() => new Image(null), /Illegal arguments for construction/); }); + + it('handling invalid color', () => { + assert.throws(() => { + new Image('100x100', 'invalid'); + }, /unrecognized color `invalid'/); + }); }); describe('pixelColor', () => {