freedomjs / freedom

Embracing a distributed web
http://freedomjs.org
Apache License 2.0
512 stars 53 forks source link

convert error to string so postMessage works #307

Closed agallant closed 8 years ago

agallant commented 8 years ago

@ryscheng @willscott

Fix https://github.com/freedomjs/freedom-pgp-e2e/issues/53

postMessage duplicates the object it is sending, but cannot do so for functions and errors. This converts errors in the message into just their string message, so postMessage behaves as expected.

coveralls commented 8 years ago

Coverage Status

Coverage remained the same at 80.468% when pulling 560aa362685c54a41a6200ab3ea07deaa218418f on soycode-fixerrorpassing into 2ed50381e54b6c2d520e828c2f637ec2867c8251 on master.

agallant commented 8 years ago

PS - for context, the demo/playground for freedom-pgp-e2e used to properly pass error messages, but stopped doing so. This fixes that (why this error came up now and wasn't a problem earlier I can't say, but I believe this is still the right fix).

agallant commented 8 years ago

@willscott chatted about this with Ray and just want to check that this seems sensible to you as well before merging, since this is a somewhat deep internals change. Thanks!

willscott commented 8 years ago

Per conversation: errors are a thing we added a bit later and so don't follow the same type-coercion enforcement as arguments and returns. It seems like we've avoided this elsewhere by rejecting with strings rather than error objects. that seems plausible to continue doing in this case as well. No strong objection to putting in the type special-cased type coercion either.

agallant commented 8 years ago

Going to go with the string approach, e.g. https://github.com/soycode/freedom-portacrypt/commit/31110f222ed8241387d4bcb27ce2752d16c9af2a

And will write up a wiki page documenting that freedom.js needs strings rather than full Error objects for message passing. Thanks!