Skip to content

Commit

Permalink
[CONJS-259] adding SqlError sqlMessage property alias for text
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Jun 2, 2023
1 parent 8ca7958 commit bb5f90e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/misc/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SqlError extends Error {
(sql ? '\nsql: ' + sql : '')
);
this.name = 'SqlError';
this.text = msg;
this.sqlMessage = msg;
this.sql = sql;
this.fatal = fatal;
this.errno = errno;
Expand All @@ -29,6 +29,10 @@ class SqlError extends Error {
this.stack += '\n From event:\n' + additionalStack.substring(additionalStack.indexOf('\n') + 1);
}
}

get text() {
return this.sqlMessage;
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions test/integration/test-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('Error', () => {
assert.equal(err.sqlState, 42000);
assert.isTrue(err.message.includes('You have an error in your SQL syntax'));
assert.isTrue(err.message.includes('sql: wrong query - parameters:[]'));
assert.isTrue(err.sqlMessage.includes('You have an error in your SQL syntax'));
}
}
conn.end();
Expand Down
6 changes: 6 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -852,9 +852,15 @@ export interface SqlError extends Error {

/**
* original error message value
* @deprecated since 3.2.0 prefer using sqlMessage for compatibility with other drivers.
*/
text: string | null;

/**
* original error message value
*/
sqlMessage: string | null;

/**
* The sql command associate
*/
Expand Down

0 comments on commit bb5f90e

Please sign in to comment.