mojotech / json-type-validation

TypeScript JSON type validation
MIT License
155 stars 15 forks source link

'runWithException' should throw instance of Error #40

Open geigerzaehler opened 5 years ago

geigerzaehler commented 5 years ago

Decoder.runWithException() throws a plain DecoderError object which is not an Error instance. This means that the error has no stack trace attached and does not play well with generic exception handling mechanisms that expect an Error instance. (In my case, the error object was logged by Sentry which failed to provide useful information like error message and stack trace.) The same issue exists with Decoder.runPromise().

I’d suggest turning DecoderError into a subclass of Error, providing it with a message, and keeping the rest of the attributes. (Maybe it would make sense to drop kind in favor of the more standard name.) This change would be backwards compatible. I’d be happy to implement the change.

yuyaryshev commented 1 year ago

Created a pull request for this: https://github.com/mojotech/json-type-validation/pull/74