{"id":"89f3486a692fd095","repo":"sidorares/node-mysql2","slug":"callback-function-is-not-available-with-promise-cl-89f348","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":"lib/promise/pool_cluster.js","lineNumber":32,"sourceCode":"    const corePoolNamespace = this.poolNamespace;\n    return new this.Promise((resolve, reject) => {\n      corePoolNamespace.getConnection((err, coreConnection) => {\n        if (err) {\n          reject(err);\n        } else {\n          resolve(new PromisePoolConnection(coreConnection, this.Promise));\n        }\n      });\n    });\n  }\n\n  query(sql, values) {\n    const corePoolNamespace = this.poolNamespace;\n    const stackHolder = captureStackHolder(\n      PromisePoolNamespace.prototype.query\n    );\n    if (typeof values === '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      corePoolNamespace.query(sql, values, done);\n    });\n  }\n\n  execute(sql, values) {\n    const corePoolNamespace = this.poolNamespace;\n    const stackHolder = captureStackHolder(\n      PromisePoolNamespace.prototype.execute\n    );\n    if (typeof values === 'function') {\n      throw new Error(\n        'Callback function is not available with promise clients.'\n      );","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/sidorares/node-mysql2/blob/5ebe8903d6aea2d8ea1490e11b52491526e50f19/lib/promise/pool_cluster.js#L14-L50","documentation":"PromisePoolNamespace.query() (returned by poolCluster.of(pattern)) checks its second argument at pool_cluster.js:31 and throws if it is a function. The promise-based pool-cluster namespace only supports the promise return signature.","triggerScenarios":"Calling poolCluster.of('node1').query('SELECT 1', cb), or passing a function in the values slot of a clustered query.","commonSituations":"Adapting callback examples for PoolCluster to the promise API, or using a PoolCluster from mysql2/promise with leftover callback arguments.","solutions":["Await the promise: const [rows] = await poolCluster.of('*').query('SELECT 1')","Pass values as an array: await poolCluster.of('*').query('SELECT ? FROM t', [col])","Use the callback PoolCluster from 'mysql2' if callbacks are required"],"exampleFix":"// before\nconst ns = poolCluster.of('*');\nns.query('SELECT 1', (err, rows) => {});\n\n// after\nconst ns = poolCluster.of('*');\nconst [rows] = await ns.query('SELECT 1');","handlingStrategy":"type-guard","validationCode":"function promiseNsQuery(ns, sql, values) {\n  if (typeof values === 'function') {\n    throw new TypeError('mysql2 promise PoolNamespace: do not pass a callback to query(); await the result');\n  }\n  return ns.query(sql, values);\n}","typeGuard":"function isCallbackArg(arg) {\n  return typeof arg === 'function';\n}","tryCatchPattern":"try {\n  const [rows] = await poolCluster.of('*').query('SELECT 1');\n} catch (err) {\n  // synchronous throw; try must wrap the call expression\n  console.error(err);\n}","preventionTips":["Treat PoolNamespace (from cluster.of()) as promise-only in mysql2/promise projects","Pass values as an array, never a function","Keep cluster code in its own module to avoid callback/promise mixups"],"tags":["promise-api","callback","api-misuse","pool-cluster"],"analyzedSha":"5ebe8903d6aea2d8ea1490e11b52491526e50f19","analyzedAt":"2026-08-03T18:58:53.602Z","schemaVersion":2}