-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Calling lock methods like .forNoKeyUpdate() or .forKeyShare() on dialects that don't support them throws a confusing TypeError. It would be clearer to throw a friendly “not supported by this dialect” error instead.
The builder sets single.lock when you call a lock method (forUpdate, forShare, forNoKeyUpdate, forKeyShare). The query compiler then does:
if (this.single.lock) {
return this[this.single.lock]();
}
If the dialect compiler doesn’t implement that method, it throws: TypeError: this[this.single.lock] is not a function
The error is confusing and looks like a Knex bug, not a clear unsupported‑feature message. It doesn’t tell the user which lock mode is unsupported. Also, the error displays in the new web site when it tries to run the query for unsupported dilalects (which is how I found this).
In lib/query/querycompiler.js, add a guard so it throws a clearer error:
if (this.single.lock) {
if (typeof this[this.single.lock] === 'function') {
return this[this.single.lock]();
}
throw new Error('Locking method not supported by this dialect');
}
Optionally, include the lock name in the message: Locking method 'forNoKeyUpdate' not supported by this dialect
This keeps behaviour the same for supported dialects and makes unsupported cases understandable.