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:
@@ -86,7 +86,8 @@ function toFile (fileOut, callback) {
|
||||
}
|
||||
} else {
|
||||
this.options.fileOut = fileOut;
|
||||
return this._pipeline(callback);
|
||||
const stack = Error();
|
||||
return this._pipeline(callback, stack);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -157,7 +158,8 @@ function toBuffer (options, callback) {
|
||||
this.options.resolveWithObject = false;
|
||||
}
|
||||
this.options.fileOut = '';
|
||||
return this._pipeline(is.fn(options) ? options : callback);
|
||||
const stack = Error();
|
||||
return this._pipeline(is.fn(options) ? options : callback, stack);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1282,7 +1284,8 @@ function _read () {
|
||||
/* istanbul ignore else */
|
||||
if (!this.options.streamOut) {
|
||||
this.options.streamOut = true;
|
||||
this._pipeline();
|
||||
const stack = Error();
|
||||
this._pipeline(undefined, stack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1291,18 +1294,30 @@ function _read () {
|
||||
* Supports callback, stream and promise variants
|
||||
* @private
|
||||
*/
|
||||
function _pipeline (callback) {
|
||||
function _pipeline (callback, stack) {
|
||||
if (typeof callback === 'function') {
|
||||
// output=file/buffer
|
||||
if (this._isStreamInput()) {
|
||||
// output=file/buffer, input=stream
|
||||
this.on('finish', () => {
|
||||
this._flattenBufferIn();
|
||||
sharp.pipeline(this.options, callback);
|
||||
sharp.pipeline(this.options, (err, data, info) => {
|
||||
if (err) {
|
||||
callback(is.nativeError(err, stack));
|
||||
} else {
|
||||
callback(null, data, info);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// output=file/buffer, input=file/buffer
|
||||
sharp.pipeline(this.options, callback);
|
||||
sharp.pipeline(this.options, (err, data, info) => {
|
||||
if (err) {
|
||||
callback(is.nativeError(err, stack));
|
||||
} else {
|
||||
callback(null, data, info);
|
||||
}
|
||||
});
|
||||
}
|
||||
return this;
|
||||
} else if (this.options.streamOut) {
|
||||
@@ -1313,7 +1328,7 @@ function _pipeline (callback) {
|
||||
this._flattenBufferIn();
|
||||
sharp.pipeline(this.options, (err, data, info) => {
|
||||
if (err) {
|
||||
this.emit('error', err);
|
||||
this.emit('error', is.nativeError(err, stack));
|
||||
} else {
|
||||
this.emit('info', info);
|
||||
this.push(data);
|
||||
@@ -1329,7 +1344,7 @@ function _pipeline (callback) {
|
||||
// output=stream, input=file/buffer
|
||||
sharp.pipeline(this.options, (err, data, info) => {
|
||||
if (err) {
|
||||
this.emit('error', err);
|
||||
this.emit('error', is.nativeError(err, stack));
|
||||
} else {
|
||||
this.emit('info', info);
|
||||
this.push(data);
|
||||
@@ -1348,7 +1363,7 @@ function _pipeline (callback) {
|
||||
this._flattenBufferIn();
|
||||
sharp.pipeline(this.options, (err, data, info) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
reject(is.nativeError(err, stack));
|
||||
} else {
|
||||
if (this.options.resolveWithObject) {
|
||||
resolve({ data, info });
|
||||
@@ -1364,7 +1379,7 @@ function _pipeline (callback) {
|
||||
return new Promise((resolve, reject) => {
|
||||
sharp.pipeline(this.options, (err, data, info) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
reject(is.nativeError(err, stack));
|
||||
} else {
|
||||
if (this.options.resolveWithObject) {
|
||||
resolve({ data, info });
|
||||
|
||||
Reference in New Issue
Block a user