-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decode shouldn't panic #7
Comments
I think if I can get #6 working the panic will just go away; however the panic is there to ensure that a bad type is not passed in for decoding because it's of type I was trying to avoid mixing decoding errors and a top level error so: err := Decode(stuff)
// was trying to avoid this...
if err == form.ErrBadInputType {
// handle error....
}
if err != nil {
// handle decode errors
} |
Hey @themihai this change has been made is in Release 2.0.0 if there are any issues please don't hesitate to reopen. |
I'm not sure you've fixed right thing here. Decoder may panic when called with nil or non-pointer param because calling it this way is an obvious bug in caller's code, and panic is here exactly for such case. At same time decoder must not panic on wrong user input (field names with unmatched brackets) - this must be handled by returning an error. |
BTW, looks like there a couple more errors should be converted to panics (because they're bugs in caller's code):
|
It seems that Decode panics if it receives invalid input. It is not idiomatic go and should be refactored using return errors. Otherwise at least the behaviour should be documented so that the caller can guard it with recover.
The text was updated successfully, but these errors were encountered: