-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error
serialization throws
#26
Comments
It might be sort of a problem since CustomError.prototype.toJSON = function () {
return {
type: 'error',
name: this.name,
message: this.message,
payload: this.payload
};
}; > JSON.stringify({err: new NotFoundError})
'{"err":{"type":"error","name":"NotFoundError","message":"Not Found","payload":{"status":404}}}'
> const trim = require('transit-immutable-js')
'use strict'
> trim.toJSON({err: new NotFoundError})
Error: Error serializing unrecognized object NotFoundError: Not Found
at transit.map.transit.makeWriteHandler.rep (/Users/nkbt/mh/ui/node_modules/transit-immutable-js/index.js:135:17)
at Object.com.cognitect.transit.impl.writer.marshal (/Users/nkbt/mh/ui/node_modules/transit-js/transit.js:2912:129)
at Object.com.cognitect.transit.impl.writer.emitMap (/Users/nkbt/mh/ui/node_modules/transit-js/transit.js:2875:115)
at Object.com.cognitect.transit.impl.writer.marshal (/Users/nkbt/mh/ui/node_modules/transit-js/transit.js:2932:50)
at Object.com.cognitect.transit.impl.writer.marshalTop (/Users/nkbt/mh/ui/node_modules/transit-js/transit.js:2950:59)
at com.cognitect.transit.impl.writer.Writer.write [as write] (/Users/nkbt/mh/ui/node_modules/transit-js/transit.js:2962:231)
at Object.toJSON (/Users/nkbt/mh/ui/node_modules/transit-immutable-js/index.js:203:21)
at repl:3:6
at ContextifyScript.Script.runInThisContext (vm.js:25:33)
at Object.exports.runInThisContext (vm.js:77:17)
> |
I'm not sure if It's probably worth exposing a way to register additional (de)serialisations for custom objects though. |
That really feels like out of scope. Also I reckon it might be quite unsafe feature to encode error without stripping away stack trace. Allowing custom serializers might be a nice thing, unless it adds too much complexity of course. |
Not sure if it is needed in general, but I ran into this today.
transit-immutable-js
falls back to "default" case"To be fair, transit-js does not serialize
Error
eitherFeel free to close if out of scope.
The text was updated successfully, but these errors were encountered: