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
@agirorn#58
I'm not a committer or a contributor but I tried to implement that. And I felt it is difficult 😢
I want to know your opinion 😄
"When you get some errors on same file and same line, but these have different messages."
Or
"When you get some errors on different file and different line, but these have same messages."
@ljharb you might be on to something here. I just did some minor experiments and have found out that node 12 (Object.keys) and object-keys do not return all the keys for all properties on an instance of the Error class.
So maybe it is just a javascript issue and then the question is should this model try to fix this strange behavior of javascript or should the user of this module just feed in the correct object that can be checked for equality?
That's because Object.keys returns only enumerable string properties; you need Object.getOwnPropertyNames + Object.getOwnPropertySymbols, or Reflect.ownKeys, to get all including non-enumerables.
The real question is, what does assert.deepEqual do? If it treats Errors as equal like this issue requests, so should this package - if not, it also should not.
node 12 assert.deepEqual treats them ass being different.
> assert.deepEqual(new Error('a'), new Error('a'))
undefined
> assert.deepEqual(new Error('a'), new Error('b'))
Thrown:
AssertionError [ERR_ASSERTION]: Expected values to be loosely deep-equal:
[Error: a]
should loosely deep-equal
[Error: b]
at repl:1:8
at Script.runInThisContext (vm.js:126:20)
at REPLServer.defaultEval (repl.js:384:29)
at bound (domain.js:415:14)
at REPLServer.runBound [as eval] (domain.js:428:12)
at REPLServer.onLine (repl.js:700:10)
at REPLServer.emit (events.js:208:15)
at REPLServer.EventEmitter.emit (domain.js:471:20)
at REPLServer.Interface._onLine (readline.js:316:10)
at REPLServer.Interface._line (readline.js:693:8) {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: [Error: a],
expected: [Error: b],
operator: 'deepEqual'
}
>
which suggests that there is, unfortunately, Error-specific checking - presumably some kind of brand check that we'll be unable to do at runtime, and that non-enumerable properties are only checked on Errors and not on normal objects.
Activity
khirayama commentedon Apr 18, 2018
@agirorn #58
I'm not a committer or a contributor but I tried to implement that. And I felt it is difficult 😢
I want to know your opinion 😄
"When you get some errors on same file and same line, but these have different messages."
Or
"When you get some errors on different file and different line, but these have same messages."
Thank you 👍
khirayama commentedon Apr 18, 2018
FYI @RusinovAnton
agirorn commentedon Oct 29, 2018
I think that errors are only equal in the following conditions:
If they are the same object
If they both of them have the error.code property and the code is equal on both of them and they both have the same error.message
If they neither of them has the error.code property and both of them have the same error.message including both massages being undefined or null
ljharb commentedon Jul 29, 2019
More that they need to have the same properties, enumerable or not - which includes
.stack.agirorn commentedon Jul 30, 2019
@ljharb you might be on to something here. I just did some minor experiments and have found out that node 12 (Object.keys) and object-keys do not return all the keys for all properties on an instance of the Error class.
So maybe it is just a javascript issue and then the question is should this model try to fix this strange behavior of javascript or should the user of this module just feed in the correct object that can be checked for equality?
As far as I'm concerned this issue can be closed.
ljharb commentedon Jul 30, 2019
That's because
Object.keysreturns only enumerable string properties; you needObject.getOwnPropertyNames+Object.getOwnPropertySymbols, orReflect.ownKeys, to get all including non-enumerables.The real question is, what does
assert.deepEqualdo? If it treats Errors as equal like this issue requests, so should this package - if not, it also should not.agirorn commentedon Jul 31, 2019
node 12
assert.deepEqualtreats them ass being different.ljharb commentedon Jul 31, 2019
I also see these:
Which suggests that it's comparing the
.message, and the[[Prototype]](like a normal object), as well as the own properties (like a normal object).I then, however, compared this:
and separately, non-enumerable properties are not compared on non-errors:
which suggests that there is, unfortunately, Error-specific checking - presumably some kind of brand check that we'll be unable to do at runtime, and that non-enumerable properties are only checked on Errors and not on normal objects.
agirorn commentedon Aug 1, 2019
Are those not all the cases that PR #48 covers for this module?
Do you think I should add more tests cases to #48 to verify that?
ljharb commentedon Aug 3, 2019
The issue is that there's no runtime way of brand-checking Error objects, and
instanceof Erroris not sufficient.