hapijs / boom

HTTP-friendly error objects
Other
2.93k stars 193 forks source link

Don't mess with instanceof checks called on subclasses #286

Closed kanongil closed 3 years ago

kanongil commented 3 years ago

This should fix the false positives reported in #285. Now any instanceof check called on a Boom subclass will effectively return false, since the actual returned object from the constructor is never a Boom object.

I used https://stackoverflow.com/a/57898482/248062 as input.

wallacethefmh commented 3 years ago

Why does the Boom constructor not return an instance of itself? imo this is just as bad a pattern as the bug you are fixing. The constructor is essentially a factory method.

devinivy commented 3 years ago

Yeah, that's exactly right— as I think about it the constructor exists for the convenience of being able to use instanceof Boom on boom errors or boomified user errors which originate outside boom. The docs (originally written in the commit closing #173) talk a little bit more about intended usage and why it works that way.