-
Notifications
You must be signed in to change notification settings - Fork 30
Description
I have discovered that thanks to Babel's limitations we can't extend the built-in Error class for our custom error class as it is not possible to use instanceof assertion on it afterward.
The solution is using the error codes that I have already proposed. The potential problem from the user-side is that users might expect the instanceof check working so we should prevent that as only documentation might not be sufficient for that.
An idea that came up to my mind is that we could not export the custom Error classes but only the error codes they represent and so "force" the users to really use code assertions instead of instanceof assertions.
UPDATE:
The original problem was most probably caused by a combination of a bug and some other weird behavior. The mentioned caveats should not be applicable to us, because this problem raises when the build target is ES5 but we are targeting ES6, but...
There is a new problem with assertions of Errors raised by NodeJS modules. They wrap all errors (even the native ones like TypeError, if interested see here) in order to support error codes and possibly other stuff. Most probably thanks to Babel/Webpack some of this wrapping is broken and simple e instanceof TypeError for TypeErrors thrown by NodeJS module won't work.
I have tested the same in browsers (I am concerned with URL class that is present both in Node and browser) and that works as expected.