pinojs / pinojs/thread-stream

Custom error objects aren't cloneable

Open
#29 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
261
Forks
31
Avg merge
2d 9h
Merged PRs (30d)
4

Description

Just something to remember... in https://github.com/pinojs/thread-stream/blob/main/lib/worker.js, when the destination error event is emitted, an 'ERROR' message is posted back to the origin thread...

https://github.com/pinojs/thread-stream/blob/main/lib/worker.js#L21-L26:

  destination.on('error', function (err) {
    parentPort.postMessage({
      code: 'ERROR',
      err
    })
  })

Error objects can be a bit odd in the structured clone algorithm. If err is a custom error object (e.g. something like Node.js DOMException or something like class MyError extends Error, what comes out on the other side will not match exactly. It will certainly clone as an Error, but you'll lose the custom extension on it.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading lib/worker.js around lines 21-26 and tracing how the ERROR message is received on the origin thread. Check the existing worker error-handling path and determine what behavior is expected for custom Error objects; done means that behavior is preserved across the thread boundary and covered by an appropriate test.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.