Skip to content

fix: preserve connection error data in the worker bridge #529

Open

Description

@electrohyun

Description

While integrating the worker client into a frontend, I found that connection errors lose their data. The message arrives, but the page cannot use the error code to show the appropriate guidance. The data should be preserved as it is with direct smocket connections.

Reproduction

import { Server } from 'smocket'
import { attachSharedWorker, connectSharedWorker } from 'smocket/shared-worker'

const server = new Server('http://example.test')
server.use((_socket, next) => {
  next(Object.assign(new Error('Session expired'), {
    data: { code: 'TOKEN_EXPIRED' },
  }))
})

const { port1, port2 } = new MessageChannel()
attachSharedWorker(server, port1)

const socket = connectSharedWorker(port2, { url: 'http://example.test' })
socket.on('connect_error', error => {
  console.log('data' in error ? error.data : undefined)
})

This prints undefined instead of the supplied error data.

smocket version

1.0.1, main at 1144eaf

Environment

Node 24.11.1. Also reproduced in Chromium.

Activity

  1. added
    bug
    on Oct 1, 2026
  2. self-assigned this
    on Oct 1, 2026
  3. moved this from Backlog to Ready in smocketon Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

  • Status
    Ready

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions