You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Attempting to console.log()DOMException.prototype throws error #60107
Linux samual-nixos 6.12.48 #1-NixOS SMP PREEMPT_DYNAMIC Fri Sep 19 14:35:52 UTC 2025 x86_64 GNU/Linux
Subsystem
Console
What steps will reproduce the bug?
Evaluate console.log(DOMException.prototype) in any way.
How often does it reproduce? Is there a required condition?
Every time.
What is the expected behavior? Why is that the expected behavior?
Simply print the object to the terminal. That's what browsers do.
What do you see instead?
Welcome to Node.js v24.8.0.
Type ".help" for more information.
> console.log(DOMException.prototype)
Uncaught TypeError: Value of "this" must be of DOMException
at throwInvalidThisError (node:internal/per_context/domexception:29:15)
at get name (node:internal/per_context/domexception:133:7)
at formatError (node:internal/util/inspect:1633:20)
at formatRaw (node:internal/util/inspect:1067:14)
at formatValue (node:internal/util/inspect:922:10)
at inspect (node:internal/util/inspect:409:10)
at formatWithOptionsInternal (node:internal/util/inspect:2574:40)
at formatWithOptions (node:internal/util/inspect:2436:10)
at console.value (node:internal/console/constructor:336:14) {
code: 'ERR_INVALID_THIS'
}
In a browser, that logs undefined, and it's a data property.
In node, Object.getOwnPropertyDescriptor(DOMException, 'prototype') also fails, and that should not even be possible.
how are you getting it to log undefined?
here's firefox:
here's chrome:
In Node.js, I assume you're trying to run it in the REPL and the REPL is trying to print the object to the terminal using the same thing console.log() uses (I assume it's using util.inspect() or whatever util.inspect() is an abstraction for).
You're right, it's the inspection that's causing the problem, and it's failing on the first key name.
I now see that if i do DOMException.prototype.name or DOMException.prototype directly in the repl, it fails, and in Safari, it just logs undefined (i guess safari's console log implementation logs undefined when it throws). Chrome does something weird and different.
The Console standard is... frustratingly silent on error handling: it says nothing about how to handle errors during printing or formatting. (Which can occur if you try to %s format an object like { toString() { throw new Error("nope") } } -- from a quick test: Firefox seems to silently discard the entire console.log() call in this case, Chrome propagates the exception).
In that case, it seems like node's well within its rights to do whatever it wants here, so while node may choose to do something different, it's not a bug as-is?
Node.js console.log() implementation could throw for every every object passed in if it wanted, that doesn't make it good or useful behaviour.
It's not a bug in the context of the spec but I don't think the spec is a good context for deciding what's a bug in this case. I think it's a bug in the context of Node.js.
Activity
ljharb commentedon Oct 2, 2025
In a browser, that logs
undefined, and it's a data property.In node,
Object.getOwnPropertyDescriptor(DOMException, 'prototype')also fails, and that should not even be possible.samualtnorman commentedon Oct 2, 2025
how are you getting it to log


undefined?here's firefox:
here's chrome:
In Node.js, I assume you're trying to run it in the REPL and the REPL is trying to print the object to the terminal using the same thing
console.log()uses (I assume it's usingutil.inspect()or whateverutil.inspect()is an abstraction for).Try
> void Object.getOwnPropertyDescriptor(DOMException, 'prototype').ljharb commentedon Oct 2, 2025
You're right, it's the inspection that's causing the problem, and it's failing on the first key
name.I now see that if i do
DOMException.prototype.nameorDOMException.prototypedirectly in the repl, it fails, and in Safari, it just logs undefined (i guess safari's console log implementation logs undefined when it throws). Chrome does something weird and different.What does the HTML spec say about this?
Fayti1703 commentedon Oct 2, 2025
WebIDL says that invoking a getter on an object that doesn't implement the appropriate interface throws a
TypeError. (The case of accessing it on theprototypeobject is directly called out elsewhere -- note thatDOMException::nameis not annotated withLegacyLenientThis). So that part seems correct.The Console standard is... frustratingly silent on error handling: it says nothing about how to handle errors during printing or formatting. (Which can occur if you try to
%sformat an object like{ toString() { throw new Error("nope") } }-- from a quick test: Firefox seems to silently discard the entireconsole.log()call in this case, Chrome propagates the exception).ljharb commentedon Oct 2, 2025
In that case, it seems like node's well within its rights to do whatever it wants here, so while node may choose to do something different, it's not a bug as-is?
samualtnorman commentedon Oct 2, 2025
Node.js
console.log()implementation could throw for every every object passed in if it wanted, that doesn't make it good or useful behaviour.It's not a bug in the context of the spec but I don't think the spec is a good context for deciding what's a bug in this case. I think it's a bug in the context of Node.js.
util: use more defensive code when inspecting error objects
util: use more defensive code when inspecting error objects
util: use more defensive code when inspecting error objects
util: use more defensive code when inspecting error objects