Skip to content
soycode edited this page Apr 26, 2016 · 3 revisions

If you're working on a freedom.js module that needs to raise errors, then depending on the purpose of the error you may want to simply use a string with the error message rather than a proper Error object.

Specifically, if the error being returned by a method being exposed to a consumer of your module via the API in the freedom.js manifest, then you should return it as a string so that the internal postMessage function used to communicate between web workers is able to pass it. postMessage duplicates whatever message it is passing, but cannot duplicate Error or function objects - hence, just use a string.

For example (as the return line of a function meant to pass a promise through a freedom.js interface):

// BAD - don't do, will fail to be passed
return Promise.reject(Error('My error message'));

// GOOD - will be passed to consuming module
return Promise.reject('My error message');

These messages themselves should be documented in your manifest under the key ERRCDODE (see freedom-pgp-e2e for an example).