jashkenas / jashkenas/underscore
Compare errors by identity in _.isEqual
- Dominant language
- JavaScript
- Stars
- 27.3k
- Forks
- 5.4k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 1
Description
*Edit bij @jgonggrijp: [tldr link](https://github.com/jashkenas/underscore/issues/2882#issuecomment-706246341).*
Is this intentional?
```javascript
var a = new Error('a')
var b = new Error('b')
_.isEqual(a, b) // true
```
This holds true for extensions as well...
```javascript
class A extends Error { constructor(message) { super(message); this.enumerable = 'Klaatu barada nikto' } }
var e1 = new A('Fear has been substituted for reason.')
var e2 = new A('Join us and live in peace')
_.isEqual(a, b) // true
```
Other built in types (e.g. Date, RegExp, Symbol) have various methods to coerce for comparison.
Error comparison ends up in deep equality comparison, which relies on Object.keys and ends up comparing empty arrays.
Happy to send in a PR if this is unintentional, also happy to work around it if it is.
Contributor guide
Research direction
Start at _.isEqual and trace the deep-equality path where Error objects are reduced to Object.keys. Compare this with the handling of other built-in types, including Error subclasses and differing messages. Done means the intended Error comparison behavior is decided and covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100