Skip to content

WebSocket: Network error cause missing #4991

@chrmarti

Description

@chrmarti

Bug Description

Regression of #4273. The test

t.assert.ok(ev.error instanceof TypeError)
passes, but there is no cause with ECONNREFUSED on the error.

Reproducible By

import { WebSocket } from 'undici';

// No actual server here
const ws = new WebSocket('ws://localhost:1234');

ws.addEventListener('error', (event) => {
  console.log('TypeError', event.error instanceof TypeError);
  console.log('error.cause', event.error?.cause);
});

Expected Behavior

Error should have a cause with the network error.

Logs & Screenshots

N/A

Environment

macOS Tahoe 26.4. Node.js 22.22.1. Undici 8.0.2.

Additional context

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions