redis / node-redis

Redis Node.js client

Home Page:https://redis.js.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Legacy command no longer call callback with error

msebire opened this issue · comments

Description

Since @redis/client 1.5.0, callback are no longer called when an error is thrown.

Issue can be reproduced using the following code:

  const client = createClient({ url, legacyMode: true });
  
  await client.connect();

  const result = await promisify(client.sendCommand).call(client, 'PING');
  console.log(`Result is ${result}`);

> OK "Result is PONG" is printed

  try {
    await promisify(client.sendCommand).call(client, 'FAIL');
  } catch (e) {
    console.log(`Error is ${e}`);
> KO, we never reach this code
  }

From what I was able to investigate, it seems the issue was introduced here: aa75ee49#diff-6674346081a0261b88e15fb0ae5a540ec522569c7310ff00a34b4b0c34a0c07aL316
as the catch mechanism to forward the error to the callback was removed.

To give you a bit more context on my use case, I encountered this issue because I use redlock as dependency of my project.
Redlock use the callback error mechanism to load scripts if they are missing.
https://github.com/mike-marcacci/node-redlock/blob/870778cd520f9649e80f74fa755ee0f12519c683/redlock.js#L455

Node.js Version

v19.4.0

Redis Server Version

6.2.10

Node Redis Version

4.6.1

Platform

windows

Logs

No response

@msebire version 4.6.2 is on npm, sorry about that

edit: BTW, I've added tests so it won't happen again..