credo-ts
credo-ts copied to clipboard
MessageValidator does not throw an instance of Error
I found out when we call:
await MessageValidator.validate(connection)
It doesn't throw instance of Error but its own ValidationError object. JS allows throwing anything (string, object, whatever). It causes a problem in tests when we're expecting an error to be thrown, it doesn't throw.
return expect(connectionService.createTrustPing(connection)).rejects.toThrowError(...)
In general, it's considered bad practice in JS and it's recommended to throw Error or an instance of Error.
It's not a big issue but I just spent half an hour investigating what's going on. Any opinions if we should address this somehow?
I found that in many places we call it inside try-catch, which is good. The question is if we shouldn't wrap it into our own validation class/function and handle the error for each call there. 🤷♂️
Yeah probably should wrap it if it's not throwing an actual error...
Good find 👍
Fixed