Skip to content

Commit

Permalink
[CONJS-165] error initial text and sql
Browse files Browse the repository at this point in the history
Errors have 2 new properties :
* text: initial error message
* sql: query (if any)

error like :
'Parameter at position 3 is not set
sql: INSERT INTO execute_missing_parameter2 values (?, ?, ?) - parameters:[1,3]
  at Object.module.exports.createError
  at ...'
will still have the same message, but 2 news properties, like:
text: 'Parameter at position 3 is not set'
sql: 'INSERT INTO execute_missing_parameter2 values (?, ?, ?) - parameters:[1,3]'
  • Loading branch information
rusher committed Jun 4, 2021
1 parent 635605c commit 6b19ca8
Show file tree
Hide file tree
Showing 27 changed files with 164 additions and 177 deletions.
8 changes: 5 additions & 3 deletions lib/cmd/batch-bulk.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class BatchBulk extends CommonBinary {
if (this.opts.timeout) {
const err = Errors.createError(
'Cannot use timeout for Batch statement',
this.sql,
false,
info,
'HY000',
Expand Down Expand Up @@ -112,10 +113,10 @@ class BatchBulk extends CommonBinary {
displaySql() {
if (this.opts && this.initialValues) {
if (this.sql.length > this.opts.debugLen) {
return 'sql: ' + this.sql.substring(0, this.opts.debugLen) + '...';
return this.sql.substring(0, this.opts.debugLen) + '...';
}

let sqlMsg = 'sql: ' + this.sql + ' - parameters:';
let sqlMsg = this.sql + ' - parameters:';
sqlMsg += '[';
for (let i = 0; i < this.initialValues.length; i++) {
if (i !== 0) sqlMsg += ',';
Expand All @@ -129,7 +130,7 @@ class BatchBulk extends CommonBinary {
sqlMsg += ']';
return sqlMsg;
}
return 'sql: ' + this.sql + ' - parameters:[]';
return this.sql + ' - parameters:[]';
}

success(val) {
Expand Down Expand Up @@ -202,6 +203,7 @@ class BatchBulk extends CommonBinary {
if (this.stack) {
err = Errors.createError(
err.message,
this.sql,
err.fatal,
info,
err.sqlState,
Expand Down
2 changes: 2 additions & 0 deletions lib/cmd/batch-rewrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class BatchRewrite extends CommonText {
if (this.opts.timeout) {
const err = Errors.createError(
'Cannot use timeout for Batch statement',
this.sql,
false,
info,
'HY000',
Expand Down Expand Up @@ -207,6 +208,7 @@ class BatchRewrite extends CommonText {
if (this.stack) {
err = Errors.createError(
err.message,
this.sql,
err.fatal,
info,
err.sqlState,
Expand Down
9 changes: 6 additions & 3 deletions lib/cmd/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class Command extends EventEmitter {
this.sending = false;
}

displaySql() {}
displaySql() {
return null;
}

/**
* Throw an an unexpected error.
Expand All @@ -36,7 +38,7 @@ class Command extends EventEmitter {
if (this.reject) {
process.nextTick(
this.reject,
Errors.createError(msg, fatal, info, sqlState, errno, this.stack, false)
Errors.createError(msg, this.displaySql(), fatal, info, sqlState, errno, this.stack, false)
);
this.resolve = null;
this.reject = null;
Expand All @@ -58,7 +60,7 @@ class Command extends EventEmitter {
if (this.reject) {
process.nextTick(
this.reject,
Errors.createError(msg, fatal, info, sqlState, errno, this.stack, false)
Errors.createError(msg, this.displaySql(), fatal, info, sqlState, errno, this.stack, false)
);
this.resolve = null;
this.reject = null;
Expand All @@ -79,6 +81,7 @@ class Command extends EventEmitter {
if (this.stack) {
err = Errors.createError(
err.message,
err.sql,
err.fatal,
info,
err.sqlState,
Expand Down
1 change: 1 addition & 0 deletions lib/cmd/handshake/auth/caching-sha2-password-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class CachingSha2PasswordAuth extends PluginAuth {
Errors.createError(
'RSA public key is not available client side. Either set option `cachingRsaPublicKey` to indicate' +
' public key path, or allow public key retrieval with option `allowPublicKeyRetrieval`',
null,
true,
info,
'08S01',
Expand Down
88 changes: 8 additions & 80 deletions lib/cmd/handshake/auth/ed25519-password-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,93 +93,21 @@ const gf = function (init) {
const gf0 = gf(),
gf1 = gf([1]),
D2 = gf([
0xf159,
0x26b2,
0x9b94,
0xebd6,
0xb156,
0x8283,
0x149a,
0x00e0,
0xd130,
0xeef3,
0x80f2,
0x198e,
0xfce7,
0x56df,
0xd9dc,
0x2406
0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e,
0xfce7, 0x56df, 0xd9dc, 0x2406
]),
X = gf([
0xd51a,
0x8f25,
0x2d60,
0xc956,
0xa7b2,
0x9525,
0xc760,
0x692c,
0xdc5c,
0xfdd6,
0xe231,
0xc0a4,
0x53fe,
0xcd6e,
0x36d3,
0x2169
0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4,
0x53fe, 0xcd6e, 0x36d3, 0x2169
]),
Y = gf([
0x6658,
0x6666,
0x6666,
0x6666,
0x6666,
0x6666,
0x6666,
0x6666,
0x6666,
0x6666,
0x6666,
0x6666,
0x6666,
0x6666,
0x6666,
0x6666
0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666,
0x6666, 0x6666, 0x6666, 0x6666
]);

const L = new Float64Array([
0xed,
0xd3,
0xf5,
0x5c,
0x1a,
0x63,
0x12,
0x58,
0xd6,
0x9c,
0xf7,
0xa2,
0xde,
0xf9,
0xde,
0x14,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0x10
0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10
]);

function reduce(r) {
Expand Down
2 changes: 1 addition & 1 deletion lib/cmd/handshake/auth/sha256-password-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Sha256PasswordAuth extends PluginAuth {
Errors.createError(
'RSA public key is not available client side. Either set option `rsaPublicKey` to indicate' +
' public key path, or allow public key retrieval with option `allowPublicKeyRetrieval`',

null,
true,
info,
'08S01',
Expand Down
3 changes: 3 additions & 0 deletions lib/cmd/handshake/handshake.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class Handshake extends Command {
"Client does not support authentication protocol '" +
pluginName +
"' requested by server. ",
null,
true,
info,
'08004',
Expand Down Expand Up @@ -237,6 +238,7 @@ class Handshake extends Command {
if (!Handshake.ensureNodeVersion(11, 6, 0)) {
throw Errors.createError(
'sha256_password authentication plugin require node 11.6+',
null,
true,
info,
'08004',
Expand All @@ -250,6 +252,7 @@ class Handshake extends Command {
if (!Handshake.ensureNodeVersion(11, 6, 0)) {
throw Errors.createError(
'caching_sha2_password authentication plugin require node 11.6+',
null,
true,
info,
'08004',
Expand Down
4 changes: 3 additions & 1 deletion lib/cmd/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class Query extends CommonText {
const err = Errors.createError(
'Cannot use timeout for MariaDB server before 10.1.2. timeout value: ' +
this.opts.timeout,
this.sql,
false,
info,
'HY000',
Expand All @@ -137,6 +138,7 @@ class Query extends CommonText {
// max_execution time exist, but only for select, and as hint
const err = Errors.createError(
'Cannot use timeout for MySQL server. timeout value: ' + this.opts.timeout,
this.sql,
false,
info,
'HY000',
Expand All @@ -161,7 +163,7 @@ class Query extends CommonText {
if (this.queryParts.length - 1 > this.values.length) {
this.emit('send_end');
this.throwNewError(
'Parameter at position ' + (this.values.length + 1) + ' is not set\n' + this.displaySql(),
'Parameter at position ' + (this.values.length + 1) + ' is not set',
false,
info,
'HY000',
Expand Down
8 changes: 5 additions & 3 deletions lib/cmd/resultset.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,13 +448,13 @@ class ResultSet extends Command {
displaySql() {
if (this.opts && this.initialValues) {
if (this.sql.length > this.opts.debugLen) {
return 'sql: ' + this.sql.substring(0, this.opts.debugLen) + '...';
return this.sql.substring(0, this.opts.debugLen) + '...';
}

let sqlMsg = 'sql: ' + this.sql + ' - parameters:';
let sqlMsg = this.sql + ' - parameters:';
return this.logParameters(sqlMsg, this.initialValues);
}
return 'sql: ' + this.sql + ' - parameters:[]';
return this.sql + ' - parameters:[]';
}

logParameters(sqlMsg, values) {
Expand Down Expand Up @@ -513,6 +513,7 @@ class ResultSet extends Command {
"' doesn't correspond to query " +
this.sql +
'. Query cancelled. Check for malicious server / proxy',
this.sql,
false,
info,
'45034',
Expand All @@ -532,6 +533,7 @@ class ResultSet extends Command {
out.writeEmptyPacket();
const error = Errors.createError(
'LOCAL INFILE command failed: ' + err.message,
this.sql,
false,
info,
'22000',
Expand Down
1 change: 1 addition & 0 deletions lib/config/connection-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class ConnectionOptions {
if (!moment.tz.zone(tzName)) {
throw Errors.createError(
"Unknown IANA timezone '" + tzName + "'.",
null,
true,
null,
'08S01',
Expand Down
2 changes: 2 additions & 0 deletions lib/connection-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ function ConnectionCallback(options) {
if (!callback) {
throw new Errors.createError(
'missing callback parameter',
null,
false,
this.info,
'HY000',
Expand All @@ -95,6 +96,7 @@ function ConnectionCallback(options) {
callback(
Errors.createError(
'Connection closed',
null,
true,
this.info,
'08S01',
Expand Down
Loading

0 comments on commit 6b19ca8

Please sign in to comment.