Skip to content

Commit 674cf50

Browse files
committed
Validate and log MySQL connection port in MysqlAdapter
Added validation for the MySQL connection port to ensure it is a number, with error handling for invalid values. Included a debug log statement to output the port being used for the connection.
1 parent b6a8182 commit 674cf50

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/db/mysql-adapter.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ export class MysqlAdapter implements DbAdapter {
3535
} else if (connectionInfo.ssl === true) {
3636
this.config.ssl = {};
3737
}
38+
// Validate port
39+
if (connectionInfo.port && typeof connectionInfo.port !== 'number') {
40+
const parsedPort = parseInt(connectionInfo.port as any, 10);
41+
if (isNaN(parsedPort)) {
42+
throw new Error(`Invalid port value for MySQL: ${connectionInfo.port}`);
43+
}
44+
this.config.port = parsedPort;
45+
}
46+
// Log the port for debugging
47+
console.error(`[DEBUG] MySQL connection will use port: ${this.config.port}`);
3848
}
3949

4050
/**

0 commit comments

Comments
 (0)