Skip to content

Commit bb5f90e

Browse files
committed
[CONJS-259] adding SqlError sqlMessage property alias for text
1 parent 8ca7958 commit bb5f90e

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

lib/misc/errors.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class SqlError extends Error {
1313
(sql ? '\nsql: ' + sql : '')
1414
);
1515
this.name = 'SqlError';
16-
this.text = msg;
16+
this.sqlMessage = msg;
1717
this.sql = sql;
1818
this.fatal = fatal;
1919
this.errno = errno;
@@ -29,6 +29,10 @@ class SqlError extends Error {
2929
this.stack += '\n From event:\n' + additionalStack.substring(additionalStack.indexOf('\n') + 1);
3030
}
3131
}
32+
33+
get text() {
34+
return this.sqlMessage;
35+
}
3236
}
3337

3438
/**

test/integration/test-error.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ describe('Error', () => {
4141
assert.equal(err.sqlState, 42000);
4242
assert.isTrue(err.message.includes('You have an error in your SQL syntax'));
4343
assert.isTrue(err.message.includes('sql: wrong query - parameters:[]'));
44+
assert.isTrue(err.sqlMessage.includes('You have an error in your SQL syntax'));
4445
}
4546
}
4647
conn.end();

types/index.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,9 +852,15 @@ export interface SqlError extends Error {
852852

853853
/**
854854
* original error message value
855+
* @deprecated since 3.2.0 prefer using sqlMessage for compatibility with other drivers.
855856
*/
856857
text: string | null;
857858

859+
/**
860+
* original error message value
861+
*/
862+
sqlMessage: string | null;
863+
858864
/**
859865
* The sql command associate
860866
*/

0 commit comments

Comments
 (0)