{"id":"68c41be5c41e41c6","repo":"sidorares/node-mysql2","slug":"callback-function-is-not-available-with-promise-cl-68c41b","errorCode":null,"errorMessage":"Callback function is not available with promise clients.","messagePattern":"Callback function is not available with promise clients\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"promise.js","lineNumber":89,"sourceCode":"      corePoolCluster.getConnection(\n        pattern,\n        selector,\n        (err, coreConnection) => {\n          if (err) {\n            reject(err);\n          } else {\n            resolve(new PromisePoolConnection(coreConnection, this.Promise));\n          }\n        }\n      );\n    });\n  }\n\n  query(sql, args) {\n    const corePoolCluster = this.poolCluster;\n    const stackHolder = captureStackHolder(PromisePoolCluster.prototype.query);\n    if (typeof args === 'function') {\n      throw new Error(\n        'Callback function is not available with promise clients.'\n      );\n    }\n    return new this.Promise((resolve, reject) => {\n      const done = makeDoneCb(resolve, reject, stackHolder);\n      corePoolCluster.query(sql, args, done);\n    });\n  }\n\n  execute(sql, args) {\n    const corePoolCluster = this.poolCluster;\n    const stackHolder = captureStackHolder(\n      PromisePoolCluster.prototype.execute\n    );\n    if (typeof args === 'function') {\n      throw new Error(\n        'Callback function is not available with promise clients.'\n      );","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/sidorares/node-mysql2/blob/5ebe8903d6aea2d8ea1490e11b52491526e50f19/promise.js#L71-L107","documentation":"PromisePoolCluster.query() (the cluster itself, not a namespace) checks its second argument at promise.js:88 and throws synchronously if it is a function. The promise-based pool cluster API returns a Promise and does not accept node-style callbacks.","triggerScenarios":"Calling poolCluster.query('SELECT 1', cb) on a cluster from require('mysql2/promise').createPoolCluster(), or passing a function where the values array is expected.","commonSituations":"Porting callback PoolCluster examples into a promise-based codebase, or mixing the two cluster API surfaces.","solutions":["Await the promise: const [rows] = await poolCluster.query('SELECT 1')","Pass values as an array: await poolCluster.query('SELECT ? FROM t', [col])","Use require('mysql2') and the callback PoolCluster if callbacks are required"],"exampleFix":"// before\npoolCluster.query('SELECT 1', (err, rows) => {});\n\n// after\nconst [rows] = await poolCluster.query('SELECT 1');","handlingStrategy":"type-guard","validationCode":"function promiseClusterQuery(cluster, sql, args) {\n  if (typeof args === 'function') {\n    throw new TypeError('mysql2 promise PoolCluster: do not pass a callback to query(); await the result');\n  }\n  return cluster.query(sql, args);\n}","typeGuard":"function isCallbackArg(arg) {\n  return typeof arg === 'function';\n}","tryCatchPattern":"try {\n  const [rows] = await poolCluster.query('SELECT 1');\n} catch (err) {\n  // synchronous throw; try must wrap the call expression\n  console.error(err);\n}","preventionTips":["Treat the promise PoolCluster (from mysql2/promise) as promise-only","Pass args as an array, never a function","Keep cluster code isolated to avoid mixing with callback examples"],"tags":["promise-api","callback","api-misuse","pool-cluster"],"analyzedSha":"5ebe8903d6aea2d8ea1490e11b52491526e50f19","analyzedAt":"2026-08-03T18:58:53.602Z","schemaVersion":2}