This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 28389 - Allow error objects to be structured-clonable
Summary: Allow error objects to be structured-clonable
Status: RESOLVED WONTFIX
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: Other other
: P3 normal
Target Milestone: Unsorted
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-01 11:58 UTC by Jake Archibald
Modified: 2016-03-16 14:00 UTC (History)
8 users (show)

See Also:


Attachments

Description Jake Archibald 2015-04-01 11:58:57 UTC
Use case: A page postMessages a worker to request a particular task be completed. That tasks fails, the worker wishes to post back the error.

The cloned error could be constructed using the message of the original.
Comment 1 Ian 'Hixie' Hickson 2015-04-07 22:38:05 UTC
The concern is that Error objects could include sensitive data (like a stack trace). But in principle I don't disagree. IIRC the JS spec is going to eventually define structure cloning, so maybe I'll punt til that.
Comment 2 Simon Pieters 2015-04-08 10:27:52 UTC
We don't protect any sensitive data by not supporting cloning of Errors, since you can just create a new plain object with the properties copied from the Error, and send that.
Comment 3 Ian 'Hixie' Hickson 2015-04-09 20:19:29 UTC
It's more accidental transfers that I would be concerned about. Obviously if someone is just sending the data across intentionally there's not much we can do.
Comment 4 Anne 2016-02-29 10:19:39 UTC
Adam, Olli, opinions?
Comment 5 Domenic Denicola 2016-02-29 13:04:00 UTC
I would like to do a TC39 proposal to make Error objects completely non-exotic (by removing the almost-entirely-unused [[ErrorData]] object). If that happens then they should become automatically structured-clonable.

That doesn't really impact DOMException though, which is exotic in its own ways.
Comment 6 Domenic Denicola 2016-02-29 19:47:19 UTC
I submitted a PR to TC39 for discussion here to make Error objects non-exotic: https://github.com/tc39/ecma262/pull/438

However, I realized this approach might actually be counterproductive to our purposes here. See discussion in that thread.
Comment 7 Adam Klein 2016-03-03 01:52:21 UTC
I don't feel like I have a horse in this race; I can't say I really understand the hazard here.
Comment 8 Olli Pettay 2016-03-10 10:24:44 UTC
This feels like an edge case. Would someone really pass error object to the other side of postMessage? (that is I guess really the only even vaguely reasonable use case for error in sc. Storing it in history state or notification or elsewhere doesn't make much sense.)

I agree with Hixie's comment 1 and comment 3.
I'm a bit worried about accidentally passing sensitive data.
And really, is there a proper use case for this?

But I don't strongly object making error object structured-clonable.
Comment 9 Anne 2016-03-10 10:30:08 UTC
FWIW, I tried to work through how this would work in terms of ECMAScript and couldn't quite figure it out. As far as I can tell there's no reliable way to get the name of a constructor of an Error object in ECMAScript so it's not quite clear to me how to clone it without making changes to ECMAScript proper.
Comment 10 Anne 2016-03-16 14:00:04 UTC
Closing this since I don't really have a good idea as to how this could work and nobody seems super compelled to have a go at it. Please don't hesitate to file a GitHub issue with a concrete proposal though. Or let me know if you think I'm wrong here.