Open annevk opened 1 year ago
You can add properties to the TypeError. That seems better?
(It's not currently possible in Web IDL, but we'd add that.)
Yeah maybe. @littledan @syg thoughts from a JS perspective?
Having said, I think that eventually standardizing messages would be good too, but if we can avoid them being the sole mechanism to rely on that would be a lot better.
You can add properties to the TypeError. That seems better?
Does this mean adding data properties to TypeError
instances created by fetch()
? I don't really see any issue with that, aside from unlikely compat issues around libraries that might be doing that already if the new property name is something common.
Does this mean adding data properties to
TypeError
instances created byfetch()
?
Yep, that's what I meant.
(Or, I guess, own accessor properties, but own data properties would make more sense.)
Node uses error.code = "SOME_FIXED_STRING"
and it's great. I would love to see that adopted on the web.
I don't see any problems with it from the JS side, though it's unlikely that errors thrown by JS would get such a property in the near future.
Do note that this can make optimizations which are formally (but not practically) unobservable suddenly be observable: right now if there's two adjacent steps which throw a TypeError and no user code runs between them, an engine can do those steps in whichever order is more convenient for it, and with this change would be required to do them in a particular order. But that's only very rarely going to be an issue, I think, and in any case users already depend on the unspecified message strings and so practically many of these things are observable anyway.
What problem are you trying to solve?
fetch()
throws aTypeError
and callers distant from thefetch()
call are having a hard time. As we cannot extendTypeError
, the current best idea is to standardize on the message: https://github.com/whatwg/fetch/issues/526.If anyone has better ideas I'd very much appreciate them.
What solutions exist today?
None.
How would you solve it?
Allow create and throw to be passed an optional message argument.
Anything else?
This vaguely relates to #1024.