Repository navigation
doc: unclear conditions under which Worker's 'messageerror' is emmited #36333
Description
Activity
- addeddocIssues and PRs related to Node.js documentation.Issues and PRs related to Node.js documentation.
on Dec 1, 2020 To be clear, I'm happy to update the docs and provide a PR. Just lacking enough knowledge on the internal c++ workings of workers.
- addedworkerIssues and PRs related to the worker_threads module and Worker API.Issues and PRs related to the worker_threads module and Worker API.
on Dec 2, 2020 @nodejs/workers
pinging @addaleax (whom I believe has the most context / understanding of this part of the code)
Look at parallel/test-crypto-key-objects-messageport.js and test/parallel/test-worker-message-port-transfer-filehandle.js
It is unclear from the documentation how one could cause/simulate
messageerrorto be emitted by the Worker.Yeah, that’s a fair point. Part of why this was was left appear unclear is that it is also unclear (to me) in the HTML spec when this event would be emitted in the browser implementations.
Currently, this event is emitted when there is an error occuring while instantiating the posted JS object on the receiving end, where there would otherwise be no way to communicate that situation.
The examples pointed to by @benjamingr are for situations in which Node.js API objects (not JS built-ins) are received in a
vm.Context, which is currently an environment in which Node.js APIs are not available. That is a known limitation for now, rather than something that is inherent to the way we build APIs. It’s also not a condition under whichmessageerrorwould be emitted on aWorker, onlyMessagePorts (because there’s no way to create aWorkerinside avm.Context).You could probably make some of the deserialization methods throw an exception in some way, and generate the event through that, for example by messing with the prototypes of Node.js API objects, but ultimately, I don’t think there’s any good way to generate these events through the public API currently.
I can’t think of any reason why deserializing a message should fail once it has been posted, except for limitations in Node.js’ builtins, so, for testing, I would currently recommend just to emit the events directly.
Reacted by naz- added a commit that references this issue
on Jan 4, 2021 - added a commit that references this issue
on Jan 12, 2021 - added a commit that references this issue
on May 1, 2021 - added a commit that references this issue
on May 22, 2026
Location
Section of the site where the content exists
Affected URL(s):
Description
Concise explanation of the problem
It is unclear from the documentation how one could cause/simulate
messageerrorto be emitted by the Worker. It would be useful to understand the conditions when it happens and also be able to simulate such situations when testing code. A concrete example when this would be helpful is in bree codebase, where test coverage has been skipped because there's no way to simulate this event.submit a pull request.