Skip to content

Missing error message on client.connect() ECONNREFUSED #2914

@chiawendt

Description

@chiawendt

Description

When attempting to connect using client.connect(), I expect the thrown error to have a meaningful message field. However, when the connection is refused, the message is an empty string.

This makes debugging difficult in environments where only err.message is logged, leading to error logs with insufficient information.

Code:

import { createClient } from "redis";

const redis = createClient({ url: "redis://localhost:12345" });

try {
  await redis.connect();
} catch (err) {
  console.log(1, err.message); // expect nonempty message, got ""
  console.log(2, err.message === ""); // got true
  console.log(3, err.name);
  console.log(4, err.code);
  console.log(5, err);
}

Stdout:

1 
2 true
3 AggregateError
4 ECONNREFUSED
5 AggregateError [ECONNREFUSED]: 
    at internalConnectMultiple (node:net:1122:18)
    at afterConnectMultiple (node:net:1689:7) {
  code: 'ECONNREFUSED',
  [errors]: [
    Error: connect ECONNREFUSED ::1:12345
        at createConnectionError (node:net:1652:14)
        at afterConnectMultiple (node:net:1682:16) {
      errno: -61,
      code: 'ECONNREFUSED',
      syscall: 'connect',
      address: '::1',
      port: 12345
    },
    Error: connect ECONNREFUSED 127.0.0.1:12345
        at createConnectionError (node:net:1652:14)
        at afterConnectMultiple (node:net:1682:16) {
      errno: -61,
      code: 'ECONNREFUSED',
      syscall: 'connect',
      address: '127.0.0.1',
      port: 12345
    }
  ]
}

Node.js Version

No response

Redis Server Version

No response

Node Redis Version

redis@5.0.0-next.6

Platform

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions