-
Notifications
You must be signed in to change notification settings - Fork 236
Unreachable code fault at config-0.14.0/src/file/format/yaml.rs:53:26 #547
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
Comments
Confirmed. Thanks for the Issue @mjaakkol! 🙏🏻 Seems like the mixture of string and integer in `"localhost:1234" is unexpected. Backtrace:
Assumed
|
Nevermind-- the underlying YAML library is "guessing" that match *value {
...
yaml::Yaml::Integer(value) => Ok(Value::new(uri, ValueKind::I64(value))),
yaml::Yaml::Boolean(value) => Ok(Value::new(uri, ValueKind::Boolean(value))),
yaml::Yaml::Hash(ref table) => {
let mut m = Map::new();
for (key, value) in table {
match key {
yaml::Yaml::String(k) => m.insert(k.to_owned(), from_yaml_value(uri, value)?),
yaml::Yaml::Integer(k) => m.insert(k.to_string(), from_yaml_value(uri, value)?),
_ => {
println!("yaml::Yaml::{:?}", key);
unreachable!() @mjaakkol if you want a quick fix, then separate |
epage
added a commit
that referenced
this issue
Mar 12, 2025
The `unreachable!` code at https://github.com/rust-cli/config-rs/blob/main/src/file/format/yaml.rs#L53 is reachable, and this PR fixes it for two simple types: reals and booleans. Prior to this change you'd get this error trying to parse the following: ``` thread '...' panicked at .../config-0.15.9/src/file/format/yaml.rs:53:26: internal error: entered unreachable code ``` The problematic case for me turned out to be float keys: ```yaml inner_float: 0.1: "float 0.1" 0.2: "float 0.2" ``` The change in this PR follows the same pattern as already exists for Strings and Integers - just parse them as strings and leave it up to the user to work out what to do with that. Personally I only need the Real support, so happy to remove the Boolean case if that's at all contentious. I decided not to look into whether you can craft a hash with the other Yaml types (below) because it's such an odd use case it didn't seam realistic! That said, #547 suggests that just treating Hash as string would have avoided that users' problem. However, converting from these types back into the exact string format they were parsed in would be difficult, so it's not clear what the right implementation would be. So getting the simpler case (reals, booleans) done feels like the right sized change to make. ``` Array(Array), Hash(Hash), Alias(usize), Null, BadValue, ``` Let me know what you think! And thanks for maintaining this useful crate :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm getting above error as
Yaml file looks like
My structure definitions for the section are:
I believe above is valid yaml (not the best looking yaml but I'll add more things to the hashtable later so the structure is needed. This worked with 0.13.x
The text was updated successfully, but these errors were encountered: