Comments (7)
from comlink.
I'd say it mostly works, but doesn't keep all information of the thrown object.
For example, I'm using PouchDB, which throws {status: 404}
. I'm running a slightly patched comlink for a few months now that retains all enumerable properties and the error message and stack (if there is one):
--- a/node_modules/comlinkjs/comlink.js
+++ b/node_modules/comlinkjs/comlink.js
@@ -27,9 +27,9 @@ const proxyTransferHandler = {
};
const throwTransferHandler = {
canHandle: (obj) => obj && obj[throwSymbol],
- serialize: (obj) => obj.toString() + "\n" + obj.stack,
+ serialize: (obj) => Object.assign({}, obj, {message: obj.message, stack: obj.stack}),
deserialize: (obj) => {
- throw Error(obj);
+ throw Object.assign(new Error(), obj);
}
};
export const transferHandlers = new Map([
from comlink.
@michael42 Good catch. You mind opening a PR? I just wanna be on the safe side legally β I donβt think I can just rip your code from your comment ;)
from comlink.
@PaulKinlan What kind of best practices are you looking for? The goal was for Comlink to behave as transparently as possible.
from comlink.
I know what the issue was now. You can't create a Symbol on a string, so when a library does throw 'sumfins wrong';
Comlink will throw an error like so Cannot create property 'Symbol(throw)' on string
from comlink.
Note that this won't work:
throw Object.assign(new Error(), obj);
if you have code like this:
} catch (error) {
throw Object.assign(new Error('Something went wrong:' + err.message), { error })
}
because error
will not be transferrable and throw when trying to post the message
from comlink.
This is now documented in the README.
from comlink.
Related Issues (20)
- Web Worker Hangs if Imported File Contains Top-Level `Await` HOT 6
- Service worker example: stops working when SW is suspended HOT 9
- Set operation is not awaitable HOT 2
- Possible to communicate between web workers? HOT 1
- How to transfer result buffers HOT 2
- [feat] DeasyncEndpoint HOT 2
- Move from Karma to Playwright? HOT 1
- Do I need to use transfer inside a proxy? HOT 1
- Add support for async transferHandle serializer/deserializer HOT 2
- Significant performance optimizations possible in `requestResponseMessage` HOT 4
- Push notifications from web worker HOT 5
- Memory leak when terminating worker with ongoing call HOT 2
- Worker Pool for similar tasks HOT 2
- Sharing constructed objects within a remote context HOT 1
- How to implement comlink in Next.js 14 App Route HOT 2
- Feature request: Automatic proxy of arguments HOT 3
- Having issues when using comlink with react (storing in react state) HOT 3
- Exposed function deadlocks if called too early
- Returning a collection - transferHandlers to be called
- How to prevent auto `releaseProxy`?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from comlink.