sidorares/node-mysql2 · error · Error
Callback function is not available with promise clients.
Error message
Callback function is not available with promise clients.
What it means
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.
Source
Thrown at lib/promise/pool_cluster.js:32
const corePoolNamespace = this.poolNamespace;
return new this.Promise((resolve, reject) => {
corePoolNamespace.getConnection((err, coreConnection) => {
if (err) {
reject(err);
} else {
resolve(new PromisePoolConnection(coreConnection, this.Promise));
}
});
});
}
query(sql, values) {
const corePoolNamespace = this.poolNamespace;
const stackHolder = captureStackHolder(
PromisePoolNamespace.prototype.query
);
if (typeof values === 'function') {
throw new Error(
'Callback function is not available with promise clients.'
);
}
return new this.Promise((resolve, reject) => {
const done = makeDoneCb(resolve, reject, stackHolder);
corePoolNamespace.query(sql, values, done);
});
}
execute(sql, values) {
const corePoolNamespace = this.poolNamespace;
const stackHolder = captureStackHolder(
PromisePoolNamespace.prototype.execute
);
if (typeof values === 'function') {
throw new Error(
'Callback function is not available with promise clients.'
);View on GitHub (pinned to 5ebe8903d6)
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
Example fix
// before
const ns = poolCluster.of('*');
ns.query('SELECT 1', (err, rows) => {});
// after
const ns = poolCluster.of('*');
const [rows] = await ns.query('SELECT 1'); Defensive patterns
Strategy: type-guard
Validate before calling
function promiseNsQuery(ns, sql, values) {
if (typeof values === 'function') {
throw new TypeError('mysql2 promise PoolNamespace: do not pass a callback to query(); await the result');
}
return ns.query(sql, values);
} Type guard
function isCallbackArg(arg) {
return typeof arg === 'function';
} Try / catch
try {
const [rows] = await poolCluster.of('*').query('SELECT 1');
} catch (err) {
// synchronous throw; try must wrap the call expression
console.error(err);
} Prevention
- 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
When it happens
Trigger: Calling poolCluster.of('node1').query('SELECT 1', cb), or passing a function in the values slot of a clustered query.
Common situations: Adapting callback examples for PoolCluster to the promise API, or using a PoolCluster from mysql2/promise with leftover callback arguments.
Related errors
- Callback function is not available with promise clients.
- Callback function is not available with promise clients.
- Callback function is not available with promise clients.
- You have tried to call .then(), .catch(), or invoked await o
- no Promise implementation available.Use promise-enabled node
AI-assisted analysis of sidorares/node-mysql2@5ebe8903d6 (2026-08-03).
Data as JSON: /data/errors/89f3486a692fd095.json.
Report an issue: GitHub.