From 674cf50db61a977e46f89a34ad1d6f86c04df556 Mon Sep 17 00:00:00 2001 From: Karthik KK Date: Sat, 31 May 2025 08:32:39 +1200 Subject: [PATCH] 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. --- src/db/mysql-adapter.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/db/mysql-adapter.ts b/src/db/mysql-adapter.ts index f2b71e1..0986da4 100644 --- a/src/db/mysql-adapter.ts +++ b/src/db/mysql-adapter.ts @@ -35,6 +35,16 @@ export class MysqlAdapter implements DbAdapter { } else if (connectionInfo.ssl === true) { this.config.ssl = {}; } + // Validate port + if (connectionInfo.port && typeof connectionInfo.port !== 'number') { + const parsedPort = parseInt(connectionInfo.port as any, 10); + if (isNaN(parsedPort)) { + throw new Error(`Invalid port value for MySQL: ${connectionInfo.port}`); + } + this.config.port = parsedPort; + } + // Log the port for debugging + console.error(`[DEBUG] MySQL connection will use port: ${this.config.port}`); } /**