Skip to content

Commit ba1b104

Browse files
committed
fix v6 error handling, add to promises[]
1 parent 865133e commit ba1b104

File tree

2 files changed

+36
-29
lines changed

2 files changed

+36
-29
lines changed

packages/client/lib/client/index.ts

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -558,33 +558,40 @@ export default class RedisClient<
558558
}
559559

560560
if (!this.#options?.disableClientInfo) {
561-
this.#queue.addCommand([
562-
'CLIENT',
563-
'SETINFO',
564-
'LIB-NAME',
565-
this.#options?.clientInfoTag
566-
? `node-redis(${this.#options.clientInfoTag})` : 'node-redis'
567-
], {
568-
chainId,
569-
asap: true
570-
}).catch(err => {
571-
// Client libraries are expected to ignore failures since they could be
572-
// connected to an older server that doesn't support them.
573-
if (err !instanceof SimpleError || !err.isUnknownCommand()) {
574-
return;
575-
}
576-
});
577-
578-
this.#queue.addCommand(['CLIENT', 'SETINFO', 'LIB-VER', version],{
579-
chainId,
580-
asap: true
581-
}).catch(err => {
582-
// Client libraries are expected to ignore failures since they could be
583-
// connected to an older server that doesn't support them.
584-
if (err !instanceof SimpleError || !err.isUnknownCommand()) {
585-
return;
586-
}
587-
});
561+
promises.push(
562+
this.#queue.addCommand([
563+
'CLIENT',
564+
'SETINFO',
565+
'LIB-NAME',
566+
this.#options?.clientInfoTag
567+
? `node-redis(${this.#options.clientInfoTag})` : 'node-redis'
568+
], {
569+
chainId,
570+
asap: true
571+
}).catch(err => {
572+
// Only throw if not a SimpleError - unknown subcommand
573+
// Client libraries are expected to ignore failures
574+
// of type SimpleError - unknown subcommand, which are
575+
// expected from older servers ( < v7 )
576+
if (!(err instanceof SimpleError) || !err.isUnknownSubcommand()) {
577+
throw err;
578+
}
579+
})
580+
);
581+
promises.push(
582+
this.#queue.addCommand(['CLIENT', 'SETINFO', 'LIB-VER', version],{
583+
chainId,
584+
asap: true
585+
}).catch(err => {
586+
// Only throw if not a SimpleError - unknown subcommand
587+
// Client libraries are expected to ignore failures
588+
// of type SimpleError - unknown subcommand, which are
589+
// expected from older servers ( < v7 )
590+
if (!(err instanceof SimpleError) || !err.isUnknownSubcommand()) {
591+
throw err;
592+
}
593+
})
594+
);
588595
}
589596

590597
const commands = await this.#handshake(this.#selectedDB);

packages/client/lib/errors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ export class ErrorReply extends Error {
6565
}
6666

6767
export class SimpleError extends ErrorReply {
68-
isUnknownCommand(): boolean {
69-
return this.message.indexOf('ERR unknown command') !== -1;
68+
isUnknownSubcommand(): boolean {
69+
return this.message.toLowerCase().indexOf('err unknown subcommand') !== -1;
7070
}
7171
}
7272

0 commit comments

Comments
 (0)