-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MULTI
does not handle commands "runtime" errors
#2665
MULTI
does not handle commands "runtime" errors
#2665
Comments
I think a possible fix for this would be this modification to transformReplies(rawReplies: Array<RedisCommandRawReply>): Array<RedisCommandRawReply> {
return rawReplies.map((reply, i) => {
+ if (reply instanceof Error) {
+ throw reply;
+ }
+
const { transformReply, args } = this.queue[i];
return transformReply ? transformReply(reply, args.preserve) : reply;
});
} I'm not very familiar with the architecture of the library to determine the best possible solution. Please note that this only occurs when using |
It seems like this is an issue with all commands that throws an error in "runtime", not something specific to // same bug...
await client.multi()
.set('key', 'value')
.hGetAll('key')
.exec(); How do you expect the client to behave in this scenario? to resolve with the error in the respective index? reject with custom error that contains all the replies? // resolve with the error:
const replies = await client.multi()
.set('key', 'value')
.hGetAll('key')
.exec();
// replies = ['OK', ErrorReply('...')]
// reject with custom error:
try {
await client.multi()
.set('key', 'value')
.hGetAll('key')
.exec();
} catch (error) {
if (error instanceof MultiReplyError) {
error.replies;
// replies = ['OK', ErrorReply('...')]
}
} possible fix: transformReplies(rawReplies: Array<RedisCommandRawReply>): Array<RedisCommandRawReply> {
const errorIndexes = [];
const replies = rawReplies.map((reply, i) => {
if (reply instanceof ReplyError) {
errorIndexes.push(i);
return reply;
}
const { transformReply, args } = this.queue[i];
return transformReply ? transformReply(reply, args.preserve) : reply;
});
if (errorIndexes.length) throw new MultiErrorReply(replies, errorIndexes);
return replies;
} |
I suspected that but didn't have enough evidence. I just wanted to put out a bug report to make sure this is captured (notice above how I'm still experimenting).
Ideally throw the exception reply from redis, as it stands currently the error is lost and it took us quite a while to figure out what happened. The solution I proposed above isn't very good as it loses the stack trace from the original call (assuming it is uncaught). Your solution looks very nice, a wrapper exception of |
MULTI
does not handle commands "runtime" errors
Description
When using XAUTOCLAIM on a non-existant key, a
TypeError
is raised because the result is incorrectly mapped.To reproduce:
I believe the issue stems from
transformReply
not handling the exception when it comes through, but it could also be a problem withhandleExecReplies
not detecting the error.Node.js Version
Any
Redis Server Version
Any
Node Redis Version
4.6.11
Platform
Any
Logs
The text was updated successfully, but these errors were encountered: