gristlabs/ts-interface-checker

Throw with TypeError instead of Error

ibc opened this issue · 6 comments

ibc commented

Since this lib checks "types" it would make more sense to have check() throw TypeError instead of a generic `Error.

Or a new object that extends TypeError, so I can identity when it's an integration error or an internal error

Currently it throws VError, which extends from Error. You can check against that. I don't mind inheriting from TypeError instead, but there are quite a few kinds of internal bugs that manifest as TypeError. E.g. "Cannot read property 'foo' of null" is a TypeError. So TypeError is not very useful to distinguish validation from internal errors.

if this thown an error based on a lib class it's exactly what i need.

The library isn't throwing the VError, it is throwing an Error native object

image

See, it ignores the instanceof VError
image

But the first line in stack trace send me to the code of VError creation...
image

Either if I instance VError it does not consider a VError instance x_____x
image

You are right, there is a deeper issue about extending Error. Could you check if this fixes the issue for you:
#27 ?

With v0.1.12, just released, you can import VError and check for it using instanceof.