Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
},
"dependencies": {
"mysql2": "^3.9.1",
"sqlstring": "^2.3.3"
"sqlstring": "^2.3.3",
"onelogger": "^1.0.0"
},
"devDependencies": {
"@eggjs/tsconfig": "^1.3.2",
Expand Down
5 changes: 5 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { promisify } from 'node:util';
import { setTimeout } from 'node:timers/promises';
import mysql, { Pool } from 'mysql2';
import type { PoolOptions } from 'mysql2';
import { getLogger } from 'onelogger';
import type { PoolConnectionPromisify, RDSClientOptions, TransactionContext, TransactionScope } from './types';
import { Operator } from './operator';
import { RDSConnection } from './connection';
Expand Down Expand Up @@ -167,6 +168,10 @@ export class RDSClient extends Operator {
if (typeof connOrTimeout === 'number') {
connPromise.then(conn => {
conn.release();
}).catch(e => {
const logger = getLogger();
e.message = 'get conn failed after timeout: ' + e.message;
logger.warn(e);
Comment on lines +173 to +174

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Mutating the original error object by modifying its message property is generally considered an anti-pattern. It can obscure the original error source and make debugging more difficult. A better approach is to log the additional context along with the original error, without changing it. This makes logs clearer and preserves the original error information for easier debugging.

Suggested change
e.message = 'get conn failed after timeout: ' + e.message;
logger.warn(e);
logger.warn(`get conn failed after timeout. Original error: ${e.message}`, e);

});
throw new PoolWaitTimeoutError(`get connection timeout after ${connOrTimeout}ms`);
}
Expand Down