Ensure resize error from C++ is wrapped

Thanks to @papandreou
This commit is contained in:
Lovell Fuller 2014-10-23 09:39:37 +01:00
parent 3e1be7a33a
commit 97fc2a2a3a
4 changed files with 14 additions and 3 deletions

View File

@ -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!

View File

@ -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": {
@ -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"

View File

@ -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;

View File

@ -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) {