{"record":{"id":"e198a688ddc0a7f3","repo":"cube-js/cube","slug":"err-tostring","errorCode":null,"errorMessage":"err.toString()","messagePattern":"err\\.toString\\(\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cubejs-jdbc-driver/src/JDBCDriver.ts","lineNumber":225,"sourceCode":"    for (const [name, value] of Object.entries(this.config.properties)) {\n      properties.putSync(name, value);\n    }\n\n    return properties;\n  }\n\n  public async testConnection() {\n    let err;\n    let connection;\n\n    try {\n      connection = await this.pool._factory.create();\n    } catch (e: any) {\n      err = e.message || e;\n    }\n\n    if (err) {\n      throw new Error(err.toString());\n    } else {\n      await this.pool._factory.destroy(connection);\n    }\n  }\n\n  protected prepareConnectionQueries() {\n    const dbTypeDescription = JDBCDriver.dbTypeDescription(this.config.dbType);\n    return this.config.prepareConnectionQueries ||\n      dbTypeDescription && dbTypeDescription.prepareConnectionQueries ||\n      [];\n  }\n\n  protected escapeDialect(): EscapeDialect {\n    const dbTypeDescription = JDBCDriver.dbTypeDescription(this.config.dbType);\n    if (dbTypeDescription?.escapeDialect) {\n      return dbTypeDescription.escapeDialect;\n    }\n","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-jdbc-driver/src/JDBCDriver.ts#L207-L243","documentation":"JDBCDriver.testConnection creates a pooled connection to validate configuration; if pool._factory.create() fails, the caught message is rethrown as a new Error(err.toString()). The message is opaque because it wraps whatever the underlying JDBC/Java layer reported (connection refused, auth failure, class not found, etc.).","triggerScenarios":"Calling testConnection() when the JDBC connection cannot be established: unreachable host/port, bad credentials, missing JDBC driver class on the classpath, or a malformed JDBC URL — anything making factory.create() throw.","commonSituations":"Database down or firewall blocking the port; wrong username/password; missing custom JAR in customClassPath so the drivername class isn't found; typo in jdbc URL.","solutions":["Read the wrapped inner message (err.toString() preserves e.message) to see the underlying JDBC error","Verify network reachability to the DB host/port (telnet/nc) and correct URL format","Verify credentials and that the drivername class is on the classpath (set customClassPath if using a custom JAR)","Fix the root cause and re-run testConnection; only wrap further if you need more context"],"exampleFix":"// before: driver class missing from classpath\nnew JDBCDriver({ drivername: 'com.mysql.cj.jdbc.Driver', url: 'jdbc:mysql://host/db' });\n// after: supply the driver jar\nnew JDBCDriver({ drivername: 'com.mysql.cj.jdbc.Driver', url: 'jdbc:mysql://host/db', customClassPath: '/path/to/mysql-connector-j-8.x.jar' });","handlingStrategy":"try-catch","validationCode":"// Pre-flight reachability + config check before testConnection\nconst url = new URL(cfg.url.replace(/^jdbc:postgresql:\\/\\//, 'http://'));\nconst net = require('net');\nnet.connect({ host: url.hostname, port: Number(url.port) })\n  .on('connect', function () { this.end(); })\n  .on('error', (e) => console.error('DB unreachable:', e.message));\nif (!cfg.drivername) throw new Error('drivername missing — testConnection will fail');","typeGuard":null,"tryCatchPattern":"try {\n  await driver.testConnection();\n} catch (e) {\n  // e.message here is the raw underlying JDBC error string (from err.toString())\n  console.error('JDBC testConnection failed with underlying error:', e.message);\n  // inspect for 'Connection refused', 'Access denied', 'ClassNotFoundException' to fix root cause\n}","preventionTips":["Include the full e.message (it is the underlying JDBC error) in alerts/logs","Pre-flight check network reachability to host:port before starting Cube","Ensure the driver JAR for drivername is present on customClassPath","Validate jdbc URL format and credentials in CI with a testConnection smoke test"],"tags":["jdbc","connection","error-handling"],"backgroundTag":"test-connection-failed","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}