credo-ts icon indicating copy to clipboard operation
credo-ts copied to clipboard

MessageValidator does not throw an instance of Error

Open jakubkoci opened this issue 3 years ago • 1 comments
trafficstars

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. 🤷‍♂️

jakubkoci avatar Mar 25 '22 13:03 jakubkoci

Yeah probably should wrap it if it's not throwing an actual error...

Good find 👍

TimoGlastra avatar Mar 26 '22 12:03 TimoGlastra

Fixed

TimoGlastra avatar Feb 14 '24 06:02 TimoGlastra