From 97fc2a2a3aafc426b80fa90882facacbd4731418 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Thu, 23 Oct 2014 09:39:37 +0100 Subject: [PATCH] Ensure resize error from C++ is wrapped Thanks to @papandreou --- README.md | 1 + package.json | 5 +++-- src/resize.cc | 2 +- test/unit/io.js | 9 +++++++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 13d3c25c..ebcc1de5 100755 --- a/README.md +++ b/README.md @@ -590,6 +590,7 @@ This module would never have been possible without the help and code contributio * [Julian Walker](https://github.com/julianwa) * [Amit Pitaru](https://github.com/apitaru) * [Brandon Aaron](https://github.com/brandonaaron) +* [Andreas Lind](https://github.com/papandreou) Thank you! diff --git a/package.json b/package.json index 98898b50..e85f8d47 100755 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "Daniel Gasienica ", "Julian Walker ", "Amit Pitaru ", - "Brandon Aaron " + "Brandon Aaron ", + "Andreas Lind " ], "description": "High performance Node.js module to resize JPEG, PNG and WebP images using the libvips library", "scripts": { @@ -45,7 +46,7 @@ "nan": "^1.3.0" }, "devDependencies": { - "mocha": "^1.21.5", + "mocha": "^2.0.0", "mocha-jshint": "^0.0.9", "istanbul": "^0.3.2", "coveralls": "^2.11.2" diff --git a/src/resize.cc b/src/resize.cc index f6cff548..d0b304a8 100755 --- a/src/resize.cc +++ b/src/resize.cc @@ -586,7 +586,7 @@ class ResizeWorker : public NanAsyncWorker { Handle argv[3] = { NanNull(), NanNull(), NanNull() }; if (!baton->err.empty()) { // Error - argv[0] = NanNew(baton->err.data(), baton->err.size()); + argv[0] = Exception::Error(NanNew(baton->err.data(), baton->err.size())); } else { int width = baton->width; int height = baton->height; diff --git a/test/unit/io.js b/test/unit/io.js index cc733d4e..20ef2c3e 100755 --- a/test/unit/io.js +++ b/test/unit/io.js @@ -198,6 +198,15 @@ describe('Input/output', function() { done(); }); + it('Fail when input is invalid Buffer', function(done) { + sharp(new Buffer([0x1, 0x2, 0x3, 0x4])) + .toBuffer(function (err) { + assert.ok(err); + assert.ok(err instanceof Error); + done(); + }); + }); + it('Promises/A+', function(done) { sharp(fixtures.inputJpg).resize(320, 240).toBuffer().then(function(data) { sharp(data).toBuffer(function(err, data, info) {