mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 15:25:07 +01:00
Improve error messages for invalid resize parameters
Dependency version bumps and doc refresh
This commit is contained in:
@@ -104,7 +104,7 @@ const resize = function resize (width, height, options) {
|
||||
if (is.integer(width) && is.inRange(width, 1, this.constructor.maximum.width)) {
|
||||
this.options.width = width;
|
||||
} else {
|
||||
throw new Error('Invalid width (1 to ' + this.constructor.maximum.width + ') ' + width);
|
||||
throw is.invalidParameterError('width', `integer between 1 and ${this.constructor.maximum.width}`, width);
|
||||
}
|
||||
} else {
|
||||
this.options.width = -1;
|
||||
@@ -113,7 +113,7 @@ const resize = function resize (width, height, options) {
|
||||
if (is.integer(height) && is.inRange(height, 1, this.constructor.maximum.height)) {
|
||||
this.options.height = height;
|
||||
} else {
|
||||
throw new Error('Invalid height (1 to ' + this.constructor.maximum.height + ') ' + height);
|
||||
throw is.invalidParameterError('height', `integer between 1 and ${this.constructor.maximum.height}`, height);
|
||||
}
|
||||
} else {
|
||||
this.options.height = -1;
|
||||
@@ -124,7 +124,7 @@ const resize = function resize (width, height, options) {
|
||||
if (is.string(kernel[options.kernel])) {
|
||||
this.options.kernel = kernel[options.kernel];
|
||||
} else {
|
||||
throw new Error('Invalid kernel ' + options.kernel);
|
||||
throw is.invalidParameterError('kernel', 'valid kernel name', options.kernel);
|
||||
}
|
||||
}
|
||||
// Interpolator
|
||||
@@ -132,7 +132,7 @@ const resize = function resize (width, height, options) {
|
||||
if (is.string(interpolator[options.interpolator])) {
|
||||
this.options.interpolator = interpolator[options.interpolator];
|
||||
} else {
|
||||
throw new Error('Invalid interpolator ' + options.interpolator);
|
||||
throw is.invalidParameterError('interpolator', 'valid interpolator name', options.interpolator);
|
||||
}
|
||||
}
|
||||
// Centre sampling
|
||||
@@ -185,7 +185,7 @@ const crop = function crop (crop) {
|
||||
// Strategy
|
||||
this.options.crop = crop;
|
||||
} else {
|
||||
throw new Error('Unsupported crop ' + crop);
|
||||
throw is.invalidParameterError('crop', 'valid crop id/name/strategy', crop);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user