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 }}
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
When assert.equal fails, I would expect to get an AssertionError. Instead, when one of the first two arguments has a circular reference in it, I get a TypeError. Here is a contrived example from a node#v0.10.33 repl:
> x = {}
{}
> x.x = x
{ x: [Circular] }
> assert.equal(x, {})
TypeError: Converting circular structure to JSON
at Object.stringify (native)
at getMessage (assert.js:75:24)
at new AssertionError (assert.js:45:37)
at fail (assert.js:92:9)
at Function.equal (assert.js:121:27)
at repl:1:9
at REPLServer.self.eval (repl.js:110:21)
at Interface.<anonymous> (repl.js:239:12)
at Interface.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)
Clearly this is happening because JSON.stringify fails on x with its circular references. Maybe something like util.inspect can be used instead, in order to replace circular references with [Circular]?
I've tested the following on both 0.10.33 and 0.11.14 and they all behave similarly for the x defined above.
In this case, the comparison has already failed, and the bad call to JSON.stringify() occurs while trying to create an error message. So, I don't think changing the comparison is the right thing to do for this issue (but could be worth bringing up on #7161).
I personally think that using util.inspect() makes sense. I put together cjihrig/node@e904589, which does exactly this. If the maintainers are interested, I can PR it.
I think using util.inspect as @chrisdickinson has implemented is a perfectly good fix, but if any maintainers think a more minimal fix (which alters existing behaviour less) is better, my PR is another option to consider.
When
assert.equal
fails, I would expect to get anAssertionError
. Instead, when one of the first two arguments has a circular reference in it, I get aTypeError
. Here is a contrived example from a node#v0.10.33 repl:Clearly this is happening because
JSON.stringify
fails onx
with its circular references. Maybe something likeutil.inspect
can be used instead, in order to replace circular references with[Circular]
?I've tested the following on both 0.10.33 and 0.11.14 and they all behave similarly for the
x
defined above.The text was updated successfully, but these errors were encountered: