mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Ensure all Error objects contain a stack prop #3653
This commit is contained in:
@@ -459,27 +459,29 @@ describe('Input/output', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Fail when input is invalid Buffer', function (done) {
|
||||
sharp(Buffer.from([0x1, 0x2, 0x3, 0x4])).toBuffer().then(function () {
|
||||
assert(false);
|
||||
done();
|
||||
}).catch(function (err) {
|
||||
assert(err instanceof Error);
|
||||
assert.strictEqual('Input buffer contains unsupported image format', err.message);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Fail when input is invalid Buffer', async () =>
|
||||
assert.rejects(
|
||||
() => sharp(Buffer.from([0x1, 0x2, 0x3, 0x4])).toBuffer(),
|
||||
(err) => {
|
||||
assert.strictEqual(err.message, 'Input buffer contains unsupported image format');
|
||||
assert(err.stack.includes('at Sharp.toBuffer'));
|
||||
assert(err.stack.includes(__filename));
|
||||
return true;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
it('Fail when input file path is missing', function (done) {
|
||||
sharp('does-not-exist').toBuffer().then(function () {
|
||||
assert(false);
|
||||
done();
|
||||
}).catch(function (err) {
|
||||
assert(err instanceof Error);
|
||||
assert.strictEqual('Input file is missing: does-not-exist', err.message);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Fail when input file path is missing', async () =>
|
||||
assert.rejects(
|
||||
() => sharp('does-not-exist').toFile('fail'),
|
||||
(err) => {
|
||||
assert.strictEqual(err.message, 'Input file is missing: does-not-exist');
|
||||
assert(err.stack.includes('at Sharp.toFile'));
|
||||
assert(err.stack.includes(__filename));
|
||||
return true;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
describe('Fail for unsupported input', function () {
|
||||
it('Undefined', function () {
|
||||
|
||||
@@ -395,13 +395,27 @@ describe('Image metadata', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Non-existent file in, Promise out', function (done) {
|
||||
sharp('fail').metadata().then(function (metadata) {
|
||||
throw new Error('Non-existent file');
|
||||
}, function (err) {
|
||||
assert.ok(!!err);
|
||||
done();
|
||||
});
|
||||
it('Non-existent file in, Promise out', async () =>
|
||||
assert.rejects(
|
||||
() => sharp('fail').metadata(),
|
||||
(err) => {
|
||||
assert.strictEqual(err.message, 'Input file is missing: fail');
|
||||
assert(err.stack.includes('at Sharp.metadata'));
|
||||
assert(err.stack.includes(__filename));
|
||||
return true;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
it('Invalid stream in, callback out', (done) => {
|
||||
fs.createReadStream(__filename).pipe(
|
||||
sharp().metadata((err) => {
|
||||
assert.strictEqual(err.message, 'Input buffer contains unsupported image format');
|
||||
assert(err.stack.includes('at Sharp.metadata'));
|
||||
assert(err.stack.includes(__filename));
|
||||
done();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('Stream in, Promise out', function (done) {
|
||||
|
||||
@@ -690,11 +690,25 @@ describe('Image Stats', function () {
|
||||
it('File input with corrupt header fails gracefully', function (done) {
|
||||
sharp(fixtures.inputJpgWithCorruptHeader)
|
||||
.stats(function (err) {
|
||||
assert.strictEqual(true, !!err);
|
||||
assert(err.message.includes('Input file has corrupt header'));
|
||||
assert(err.stack.includes('at Sharp.stats'));
|
||||
assert(err.stack.includes(__filename));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Stream input with corrupt header fails gracefully', function (done) {
|
||||
fs.createReadStream(fixtures.inputJpgWithCorruptHeader).pipe(
|
||||
sharp()
|
||||
.stats(function (err) {
|
||||
assert(err.message.includes('Input buffer has corrupt header'));
|
||||
assert(err.stack.includes('at Sharp.stats'));
|
||||
assert(err.stack.includes(__filename));
|
||||
done();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('File input with corrupt header fails gracefully, Promise out', function () {
|
||||
return sharp(fixtures.inputJpgWithCorruptHeader)
|
||||
.stats().then(function (stats) {
|
||||
|
||||
Reference in New Issue
Block a user