Skip to content

Compare errors by identity in _.isEqual #2882

@randym

Description

@randym

Edit bij @jgonggrijp: tldr link.

Is this intentional?

var a = new Error('a')
var b = new Error('b')
_.isEqual(a, b) // true

This holds true for extensions as well...

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions