Skip to content

Commit 37c04de

Browse files
[PECO-444] Fix error logging bug (#89)
Signed-off-by: Levko Kravets <levko.ne@gmail.com> Signed-off-by: Levko Kravets <levko.ne@gmail.com>
1 parent ca4f539 commit 37c04de

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/DBSQLClient.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,15 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient {
9494
this.client = this.thrift.createClient(TCLIService, this.connection.getConnection());
9595

9696
this.connection.getConnection().on('error', (error: Error) => {
97-
this.logger.log(LogLevel.error, JSON.stringify(error));
98-
this.emit('error', error);
97+
// Error.stack already contains error type and message, so log stack if available,
98+
// otherwise fall back to just error type + message
99+
this.logger.log(LogLevel.error, error.stack || `${error.name}: ${error.message}`);
100+
try {
101+
this.emit('error', error);
102+
} catch (e) {
103+
// EventEmitter will throw unhandled error when emitting 'error' event.
104+
// Since we already logged it few lines above, just suppress this behaviour
105+
}
99106
});
100107

101108
this.connection.getConnection().on('reconnecting', (params: { delay: number; attempt: number }) => {

0 commit comments

Comments
 (0)