Skip to content

Commit 4d516fa

Browse files
committed
fix v6 error handling, add to promises[]
1 parent 81e2b34 commit 4d516fa

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
@@ -548,33 +548,40 @@ export default class RedisClient<
548548
}
549549

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

580587
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)