Simplify recent error message refactoring
This commit is contained in:
parent
51c0b81681
commit
28adf00d8b
16
lib/util.js
16
lib/util.js
|
@ -48,7 +48,7 @@ const errorMessages = {
|
|||
'NJS-002': 'NJS-002: invalid pool',
|
||||
'NJS-004': 'NJS-004: invalid value for property %s',
|
||||
'NJS-005': 'NJS-005: invalid value for parameter %d',
|
||||
'NJS-009': 'NJS-009: invalid number of parameters: %d passed but %d expected',
|
||||
'NJS-009': 'NJS-009: invalid number of parameters',
|
||||
'NJS-037': 'NJS-037: incompatible type of value provided',
|
||||
'NJS-040': 'NJS-040: connection request timeout. Request exceeded queueTimeout of %d',
|
||||
'NJS-041': 'NJS-041: cannot convert ResultSet to QueryStream after invoking methods',
|
||||
|
@ -61,7 +61,6 @@ const errorMessages = {
|
|||
'NJS-065': 'NJS-065: connection pool was closed',
|
||||
'NJS-067': 'NJS-067: a pre-built node-oracledb binary was not found for %s',
|
||||
'NJS-069': 'NJS-069: node-oracledb %s requires Node.js %s or later',
|
||||
'NJS-076': 'NJS-076: invalid number of parameters: %d passed but %d to %d expected',
|
||||
};
|
||||
|
||||
// getInstallURL returns a string with installation URL
|
||||
|
@ -154,14 +153,8 @@ module.exports.assert = assert;
|
|||
// optional parameters (range of number of parameters). If the number of
|
||||
// arguments is not within the given range, an error is thrown.
|
||||
function checkArgCount(args, minArgCount, maxArgCount) {
|
||||
if (args.length < minArgCount || args.length > maxArgCount) {
|
||||
if (minArgCount == maxArgCount) {
|
||||
throw new Error(getErrorMessage('NJS-009', args.length, minArgCount));
|
||||
} else {
|
||||
throw new Error (getErrorMessage('NJS-076', args.length,
|
||||
minArgCount, maxArgCount));
|
||||
}
|
||||
}
|
||||
if (args.length < minArgCount || args.length > maxArgCount)
|
||||
throw new Error(getErrorMessage('NJS-009'));
|
||||
}
|
||||
|
||||
module.exports.checkArgCount = checkArgCount;
|
||||
|
@ -212,8 +205,7 @@ function promisify(oracledb, func) {
|
|||
|
||||
// Check for invalid number or type of parameter(s) as they should be
|
||||
// eagerly thrown.
|
||||
if (errorCode === 'NJS-009' || errorCode === 'NJS-005' ||
|
||||
errorCode === 'NJS-076' ) {
|
||||
if (errorCode === 'NJS-009' || errorCode === 'NJS-005') {
|
||||
// Throwing the error outside of the promise wrapper so that its not
|
||||
// swallowed up as a rejection.
|
||||
process.nextTick(function() {
|
||||
|
|
|
@ -33,7 +33,7 @@ static const char *njsErrorMessages[] = {
|
|||
"NJS-004: invalid value for property %s", // errInvalidPropertyValue
|
||||
"NJS-005: invalid value for parameter %d", // errInvalidParameterValue
|
||||
"NJS-007: invalid value for \"%s\" in parameter %d", // errInvalidPropertyValueInParam
|
||||
"NJS-009: invalid number of parameters: %d passed but %d expected", // errInvalidNumberOfParameters
|
||||
"NJS-009: invalid number of parameters", // errInvalidNumberOfParameters
|
||||
"NJS-010: unsupported data type %d in column %u", // errUnsupportedDataType
|
||||
"NJS-011: encountered bind value and type mismatch", // errBindValueAndTypeMismatch
|
||||
"NJS-012: encountered invalid bind data type in parameter %d", // errInvalidBindDataType
|
||||
|
@ -82,7 +82,6 @@ static const char *njsErrorMessages[] = {
|
|||
"NJS-073: cannot convert from JavaScript value to element of type %.*s", // errConvertToObjElement
|
||||
"NJS-074: cannot convert from JavaScript value to attribute \"%.*s\" of type \"%.*s\"", // errConvertToObjAttr
|
||||
"NJS-075: only one of connectString and connectionString can be used", // errDblConnectionString
|
||||
"NJS-076: invalid number of parameters: %d passed but %d to %d expected", //errInvalidNumberOfParametersRange
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -192,7 +192,6 @@ typedef enum {
|
|||
errConvertToObjElement,
|
||||
errConvertToObjAttr,
|
||||
errDblConnectionString,
|
||||
errInvalidNumberOfParametersRange,
|
||||
|
||||
|
||||
// New ones should be added here
|
||||
|
|
|
@ -225,7 +225,7 @@ describe('14. stream2.js', function() {
|
|||
function() {
|
||||
connection.queryStream();
|
||||
},
|
||||
/NJS-076: invalid number of parameters/
|
||||
/NJS-009: invalid number of parameters/
|
||||
);
|
||||
done();
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue