Skip to content

Commit

Permalink
Ensure resize error from C++ is wrapped
Browse files Browse the repository at this point in the history
Thanks to @papandreou
  • Loading branch information
lovell committed Oct 23, 2014
1 parent 3e1be7a commit 97fc2a2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"Daniel Gasienica <daniel@gasienica.ch>",
"Julian Walker <julian@fiftythree.com>",
"Amit Pitaru <pitaru.amit@gmail.com>",
"Brandon Aaron <hello.brandon@aaron.sh>"
"Brandon Aaron <hello.brandon@aaron.sh>",
"Andreas Lind <andreas@one.com>"
],
"description": "High performance Node.js module to resize JPEG, PNG and WebP images using the libvips library",
"scripts": {
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/resize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ class ResizeWorker : public NanAsyncWorker {
Handle<Value> argv[3] = { NanNull(), NanNull(), NanNull() };
if (!baton->err.empty()) {
// Error
argv[0] = NanNew<String>(baton->err.data(), baton->err.size());
argv[0] = Exception::Error(NanNew<String>(baton->err.data(), baton->err.size()));
} else {
int width = baton->width;
int height = baton->height;
Expand Down
9 changes: 9 additions & 0 deletions test/unit/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 97fc2a2

Please sign in to comment.