mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Improve consistency of validation error handling
Utilises common path of existing invalidParameterError
This commit is contained in:
@@ -55,7 +55,7 @@ function rotate (angle, options) {
|
||||
];
|
||||
}
|
||||
} else {
|
||||
throw new Error('Unsupported angle: must be a number.');
|
||||
throw is.invalidParameterError('angle', 'numeric', angle);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -109,7 +109,7 @@ function sharpen (sigma, flat, jagged) {
|
||||
if (is.number(flat) && is.inRange(flat, 0, 10000)) {
|
||||
this.options.sharpenFlat = flat;
|
||||
} else {
|
||||
throw new Error('Invalid sharpen level for flat areas (0.0 - 10000.0) ' + flat);
|
||||
throw is.invalidParameterError('flat', 'number between 0 and 10000', flat);
|
||||
}
|
||||
}
|
||||
// Control over jagged areas
|
||||
@@ -117,11 +117,11 @@ function sharpen (sigma, flat, jagged) {
|
||||
if (is.number(jagged) && is.inRange(jagged, 0, 10000)) {
|
||||
this.options.sharpenJagged = jagged;
|
||||
} else {
|
||||
throw new Error('Invalid sharpen level for jagged areas (0.0 - 10000.0) ' + jagged);
|
||||
throw is.invalidParameterError('jagged', 'number between 0 and 10000', jagged);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new Error('Invalid sharpen sigma (0.01 - 10000) ' + sigma);
|
||||
throw is.invalidParameterError('sigma', 'number between 0.01 and 10000', sigma);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -141,7 +141,7 @@ function median (size) {
|
||||
// Numeric argument: specific sigma
|
||||
this.options.medianSize = size;
|
||||
} else {
|
||||
throw new Error('Invalid median size ' + size);
|
||||
throw is.invalidParameterError('size', 'integer between 1 and 1000', size);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -165,7 +165,7 @@ function blur (sigma) {
|
||||
// Numeric argument: specific sigma
|
||||
this.options.blurSigma = sigma;
|
||||
} else {
|
||||
throw new Error('Invalid blur sigma (0.3 - 1000.0) ' + sigma);
|
||||
throw is.invalidParameterError('sigma', 'number between 0.3 and 1000', sigma);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -205,7 +205,7 @@ function gamma (gamma, gammaOut) {
|
||||
} else if (is.number(gamma) && is.inRange(gamma, 1, 3)) {
|
||||
this.options.gamma = gamma;
|
||||
} else {
|
||||
throw new Error('Invalid gamma correction (1.0 to 3.0) ' + gamma);
|
||||
throw is.invalidParameterError('gamma', 'number between 1.0 and 3.0', gamma);
|
||||
}
|
||||
if (!is.defined(gammaOut)) {
|
||||
// Default gamma correction for output is same as input
|
||||
@@ -213,7 +213,7 @@ function gamma (gamma, gammaOut) {
|
||||
} else if (is.number(gammaOut) && is.inRange(gammaOut, 1, 3)) {
|
||||
this.options.gammaOut = gammaOut;
|
||||
} else {
|
||||
throw new Error('Invalid output gamma correction (1.0 to 3.0) ' + gammaOut);
|
||||
throw is.invalidParameterError('gammaOut', 'number between 1.0 and 3.0', gammaOut);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -315,7 +315,7 @@ function threshold (threshold, options) {
|
||||
} else if (is.integer(threshold) && is.inRange(threshold, 0, 255)) {
|
||||
this.options.threshold = threshold;
|
||||
} else {
|
||||
throw new Error('Invalid threshold (0 to 255) ' + threshold);
|
||||
throw is.invalidParameterError('threshold', 'integer between 0 and 255', threshold);
|
||||
}
|
||||
if (!is.object(options) || options.greyscale === true || options.grayscale === true) {
|
||||
this.options.thresholdGrayscale = true;
|
||||
@@ -346,7 +346,7 @@ function boolean (operand, operator, options) {
|
||||
if (is.string(operator) && is.inArray(operator, ['and', 'or', 'eor'])) {
|
||||
this.options.booleanOp = operator;
|
||||
} else {
|
||||
throw new Error('Invalid boolean operator ' + operator);
|
||||
throw is.invalidParameterError('operator', 'one of: and, or, eor', operator);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -364,17 +364,15 @@ function linear (a, b) {
|
||||
} else if (is.number(a)) {
|
||||
this.options.linearA = a;
|
||||
} else {
|
||||
throw new Error('Invalid linear transform multiplier ' + a);
|
||||
throw is.invalidParameterError('a', 'numeric', a);
|
||||
}
|
||||
|
||||
if (!is.defined(b)) {
|
||||
this.options.linearB = 0.0;
|
||||
} else if (is.number(b)) {
|
||||
this.options.linearB = b;
|
||||
} else {
|
||||
throw new Error('Invalid linear transform offset ' + b);
|
||||
throw is.invalidParameterError('b', 'numeric', b);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -405,7 +403,7 @@ function recomb (inputMatrix) {
|
||||
inputMatrix[2].length !== 3
|
||||
) {
|
||||
// must pass in a kernel
|
||||
throw new Error('Invalid Recomb Matrix');
|
||||
throw new Error('Invalid recombination matrix');
|
||||
}
|
||||
this.options.recombMatrix = [
|
||||
inputMatrix[0][0], inputMatrix[0][1], inputMatrix[0][2],
|
||||
|
||||
Reference in New Issue
Block a user