JohnWeisz / TypedJSON

Typed JSON parsing and serializing for TypeScript that preserves type information.
MIT License
603 stars 64 forks source link

[Discussion] Handling of errors #165

Open MatthiasKunnen opened 3 years ago

MatthiasKunnen commented 3 years ago

I want to start a discussion about error handling in the TypedJSON.

In my opinion, TypedJSON is too lax regarding default error behavior.

My proposal:

I'd love your opinion @Neos3452.

Neos3452 commented 3 years ago

I totally agree with the first point.

For the second, I have mixed feelings. On a frontend, you want to keep going as far as possible. It is not reasonable to error out on a parsing error, and potentially prevent a user from completing a purchase. On the other hand you want to catch such errors as soon as possible — in dev, or in tests. However, from experience silent errors were a real hinderance when undefined randomly cropped into different layers.

MatthiasKunnen commented 3 years ago

Personally, I am a fan of erroring early. Ignoring a problem in an early stage with the hope of things turning out okay almost always causes problems down the line. That being said, I believe we can keep the optimistic behavior available using the custom error handler. People that want the old behavior can use setGlobalConfig({errorHandler: console.error}). I would recommend the default behavior to error, though, for the reasons mentioned point 2 and the silent errors being a hindrance as you said.

Regardless of whether we change the default behavior, both points are a breaking change and will require a new major version.

MatthiasKunnen commented 3 years ago

WIP: https://github.com/JohnWeisz/TypedJSON/compare/master...MatthiasKunnen:error-handling