-
Notifications
You must be signed in to change notification settings - Fork 320
Always return empty map instead of nil when conversion fails #283
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
Conversation
|
|
|
Friendly ping @sagikazarmark would appreciate feedback/fix. |
|
Well...it's not an easy question. The library is not consistent about return values. I guess I tried to follow a pattern with that change. I have to look through the library to figure out what pattern is used the most. But I'd say relying on a return value when an error is returned is generally not a good idea. |
Yes ... but ... no. The bug in evcc comes from viper.GetStringMapString That calls cast.ToStringMapString And when you look at the code, you can see the code of https://github.com/spf13/cast/blob/v1.9.2/zz_generated.go So based on that, reverting the previous behavior is the least we can do. So I agree with @andig |
|
I feel like tests should be added to prevent such issues in the future https://github.com/spf13/cast/blob/v1.9.2/zz_generated.go These generated files could be tested, but it would require to update https://github.com/spf13/cast/blob/v1.9.2/generator%2Fmain.go Or maybe to manually create zz_test.go to test the few ones that could fail Or simply add tests to every single methods involved in this file. I'm unsure what would be the thing to do. Maybe both. |
|
Readme says
I seem to recall it saying something about „useful zero value“, but can‘t find that anymore. So nil may be expected from that perspective. I any case it is an unannounced, breaking behavior change causing bugs. |
|
After sleeping on it, I don't actually see the harm in returning an empty map/slice upon error. But I think it should be consistent across all functions:
@andig would you mind going through the library to make sure it's done? |
|
Afaikt, maps are the odd outlier. I wouldn't care about nil slices since I'd need to
I've had a look in the past and it's beyond my grasp, sorry. If you really want have nil maps that's probably a fair choice in terms of consistency, but imho warrants a major version and announcement to not get hit in the face ;). |
|
Much appreciated, thank you! |
|
I'm not sure how this passed CI, but tests are breaking all over now. |
|
Fixed |
|
I'm sorry, no idea :O |
Fix #282, partially reverts #269