Merge pull request #178 from ewrayjohnson/master

Fix assertion timeout logging huge parameters
This commit is contained in:
Miroslav Bajtoš 2020-07-31 17:02:19 +02:00 committed by GitHub
commit ea9c15122c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 5 deletions

View File

@ -5,6 +5,7 @@
'use strict'; 'use strict';
const assert = require('assert'); const assert = require('assert');
const util = require('util');
const PLACEHOLDER = '?'; const PLACEHOLDER = '?';
module.exports = ParameterizedSQL; module.exports = ParameterizedSQL;
@ -35,11 +36,19 @@ function ParameterizedSQL(sql, params) {
assert(Array.isArray(this.params), 'params must be an array'); assert(Array.isArray(this.params), 'params must be an array');
const parts = this.sql.split(PLACEHOLDER); const parts = this.sql.split(PLACEHOLDER);
assert(parts.length - 1 === this.params.length, if (parts.length - 1 !== this.params.length) {
'The number of ? (' + (parts.length - 1) + throw new assert.AssertionError({
') in the sql (' + this.sql + ') must match the number of params (' + message: util.format(
this.params.length + 'The number of ? (%s) in the sql (%s) must match the number of params (%s) %o',
') ' + this.params); parts.length - 1,
this.sql,
this.params.length,
this.params,
),
actual: this.params.length,
expected: parts.length - 1,
});
}
} }
/** /**