Skip to content

Commit 97fc2a2

Browse files
committed
Ensure resize error from C++ is wrapped
Thanks to @papandreou
1 parent 3e1be7a commit 97fc2a2

4 files changed

Lines changed: 14 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ This module would never have been possible without the help and code contributio
590590
* [Julian Walker](https://github.com/julianwa)
591591
* [Amit Pitaru](https://github.com/apitaru)
592592
* [Brandon Aaron](https://github.com/brandonaaron)
593+
* [Andreas Lind](https://github.com/papandreou)
593594

594595
Thank you!
595596

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"Daniel Gasienica <daniel@gasienica.ch>",
1111
"Julian Walker <julian@fiftythree.com>",
1212
"Amit Pitaru <pitaru.amit@gmail.com>",
13-
"Brandon Aaron <hello.brandon@aaron.sh>"
13+
"Brandon Aaron <hello.brandon@aaron.sh>",
14+
"Andreas Lind <andreas@one.com>"
1415
],
1516
"description": "High performance Node.js module to resize JPEG, PNG and WebP images using the libvips library",
1617
"scripts": {
@@ -45,7 +46,7 @@
4546
"nan": "^1.3.0"
4647
},
4748
"devDependencies": {
48-
"mocha": "^1.21.5",
49+
"mocha": "^2.0.0",
4950
"mocha-jshint": "^0.0.9",
5051
"istanbul": "^0.3.2",
5152
"coveralls": "^2.11.2"

src/resize.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ class ResizeWorker : public NanAsyncWorker {
586586
Handle<Value> argv[3] = { NanNull(), NanNull(), NanNull() };
587587
if (!baton->err.empty()) {
588588
// Error
589-
argv[0] = NanNew<String>(baton->err.data(), baton->err.size());
589+
argv[0] = Exception::Error(NanNew<String>(baton->err.data(), baton->err.size()));
590590
} else {
591591
int width = baton->width;
592592
int height = baton->height;

test/unit/io.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,15 @@ describe('Input/output', function() {
198198
done();
199199
});
200200

201+
it('Fail when input is invalid Buffer', function(done) {
202+
sharp(new Buffer([0x1, 0x2, 0x3, 0x4]))
203+
.toBuffer(function (err) {
204+
assert.ok(err);
205+
assert.ok(err instanceof Error);
206+
done();
207+
});
208+
});
209+
201210
it('Promises/A+', function(done) {
202211
sharp(fixtures.inputJpg).resize(320, 240).toBuffer().then(function(data) {
203212
sharp(data).toBuffer(function(err, data, info) {

0 commit comments

Comments
 (0)