Schema errors should not panic #152
Replies: 2 comments 3 replies
-
|
Hey! Thanks for your kind words! I'm sorry you find it annoying. I guess we are missing a lot of good panic messages that's something I should fix for sure. Changing the panics into errors is something that has been suggested before. And I am open to doing it if enough people want it or if I feel you can make a strong enough case for it. But Zog panicking was a very early design decision inspired by tiger style. When it panics its because you have meaningfully broken the rules of the world and generated a schema that could never succeed in parsing or validation. Having said that, I'm happy to discuss further and to change my mind on this. Regardless of what we do I agree wholeheartedly that Zog needs better error messages for this cases (be it in a panic or a regular error). |
Beta Was this translation helpful? Give feedback.
-
|
Maybe we could also do like a schema.MustCompile() or something like this. Where you pass it the structure you plan to validate and it will error out during compilation or startup instead of at runtime |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
First off, thanks for this library - I was using a similar style, home-grown solution for a project but it was nowhere near as feature-rich. I'm really loving Zog!
One thing that stands out to me at the moment is that schema errors
panic(), but I feel like they should just be part of the normal error flow (returned to caller), but maybe they can be wrapped with a custom error type, eg.zog.SchemaErroror a specific error type for the error, egzog.InvalidTypeCastError. This would make it much easier to handle in development, and should act just like any other fallable process (eg. type casting, accessing an array element). Maybe the panic behaviour could be kept in azog.MustValidatehelper function for people who like the current behaviour?I understand the idea that this is more of a 'type-level' error, but panics are really hard to to handle, especially when validation is deep in your application, and generally they only make sense for child go routines or really hard-crashing your app.
Also I don't recall seeing any specific error message in the panics at the moment so it means I have to hunt down the method then start removing/tweaking parts of the schema until it works. At the moment I'm bumping into a lot of these occasions where I'm accidentally trying to check a new type (wrapper around string or UUID) but due to lack of custom schemas, my validation
panics.Happy to try and put together a PoC if it helps?
Beta Was this translation helpful? Give feedback.
All reactions