{"record":{"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":"validation","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/8b1f829d3706404ab372cf97bd77ebcf86578d97/lib/promise/pool_cluster.js#L14-L50","documentation":"PromisePoolNamespace.query() — the query method on a namespace obtained from poolCluster.of(pattern) in the promise API — throws synchronously when values is a function. The pool-cluster promise layer does not support callbacks; passing one signals API mixing.","triggerScenarios":"const cluster = createPoolCluster({}); cluster.add('node1', {...}); const ns = (await cluster).of('node1'); ns.query('SELECT 1', (err, rows) => {...}).","commonSituations":"Using pool clusters (multi-node/routed) and porting callback query code; helpers that wrap a namespace and forward a callback; copy-paste from callback cluster examples.","solutions":["Await the result: const [rows] = await ns.query(sql).","Use the callback PoolCluster API (require('mysql2').createPoolCluster) if callbacks are required.","Catch the synchronous throw with try/catch around the call."],"exampleFix":"// before\nconst ns = cluster.of('*');\nns.query('SELECT 1', (err, rows) => { /* ... */ });\n// after\nconst ns = cluster.of('*');\nconst [rows] = await ns.query('SELECT 1');","handlingStrategy":"type-guard","validationCode":"if (typeof values === 'function') {\n  throw new TypeError('pool namespace query() in the promise API does not accept a callback; use await');\n}","typeGuard":"function isPromisePoolNamespace(ns) {\n  return ns != null && 'Promise' in ns && 'poolNamespace' in ns;\n}","tryCatchPattern":"try {\n  const [rows] = await ns.query(sql, values);\n} catch (err) {\n  if (/Callback function is not available/.test(err.message)) {\n    // drop callback, use await\n  } else {\n    throw err;\n  }\n}","preventionTips":["Remember that poolCluster.of() returns a promise namespace; treat it like any promise client.","Document which cluster helpers are promise-based vs callback-based.","Migrate cluster code in one pass to avoid mixing patterns."],"tags":["promise-api","callback","api-misuse","pool-cluster","migration"],"backgroundTag":null,"analyzedSha":"8b1f829d3706404ab372cf97bd77ebcf86578d97","analyzedAt":"2026-08-11T02:54:28.964Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}