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.
This commit is contained in:
Karthik KK
2025-05-31 08:32:39 +12:00
parent b6a8182538
commit 674cf50db6

View File

@@ -35,6 +35,16 @@ export class MysqlAdapter implements DbAdapter {
} else if (connectionInfo.ssl === true) { } else if (connectionInfo.ssl === true) {
this.config.ssl = {}; 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}`);
} }
/** /**