-
Notifications
You must be signed in to change notification settings - Fork 191
Do not panic on string conversions in yaml unmarshaling. #108
Conversation
Sounds fair 😉 |
If I understand correctly, this will treat Does it also cast all numbers to strings? Wouldn't this be better handled by #99 ? |
@vdemeester The test does test unmarshaling does not panic. @dnephin It does cast everything to string, instead of raising panics. I was thinking: the input file is text (readable and writable by humans) and the target datatype is string, so why not just use the string representation of the value. On the other hand, the orthodox docker-compose does issue an error, and |
Returning errors on incorrect datatypes now. |
@vdemeester @dnephin @ibuildthecloud I believe I've addressed the comments so far. |
parts[k] = sv | ||
} else { | ||
return fmt.Errorf("Cannot unmarshal '%v' of type %T into a string value", v, v) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block (including some of the existing lines) are repeated in quite a few places. Could we make this a function?
func ToStringSlice(value []interface{}) ([]string, error) {
...
}
Then many of these can be just:
if s.parts, err = BuildParts(value); err != nil {
return err
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
I'm not that familiar with this yaml parser. Why is it necessary that these values are cast to strings? Aren't they already strings? Is it trying to deal with cases where yaml treats them as numbers instead of strings? |
Parsed values can be anything: bool, integer, string. Consider this YAML list value, for example: [1, "sick", list, of, false, assumptions] Suppose, we have our own data type that uses
We've got an int, and a bool along with strings. So we have two options:
|
Return errors instead. Signed-off-by: Ivan Mikushin <i.mikushin@gmail.com>
Done again. |
I think this is what the strict yaml validation should be doing for us. |
Schema validation makes sure each element of the
So, I propose checking for type casting errors (that's what this code is doing now) and drop these checks when the strict yaml validation is in. Pick one 🎲 |
@vdemeester Opinions welcome 😄 |
I'm trying to think what is the correct behavior here. docker-compose doesn't actually blow up if you pass
The parser succeeds but then the Docker API itself will then blow up with some go marshaling API error. So I kind of lean towards doing the same thing. This change makes our parser more pedantic than docker-compose itself. @dnephin WDYT? |
I think in 1.5.2, it should give a warning when a boolean is used. Previously we were only warning for booleans in the I'm happy with more pedantic, as I think that's the direction that compose is going. |
@dnephin It's a hard pill to swallow for me that |
@dnephin I've been reading through the yaml spec and understand now the complexities. |
LGTM |
@vdemeester Merge? 😉 |
@imikushin yes 😝 |
Do not panic on string conversions in yaml unmarshaling.
Thx! On Tue, Dec 8, 2015, 14:52 Vincent Demeester notifications@github.com
|
Do not panic on string conversions in yaml unmarshaling.
Signed-off-by: Ivan Mikushin i.mikushin@gmail.com