Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Error deserializing: missing field when chaining load_file&resolve #48

Open
david-bouyssie opened this issue Apr 13, 2021 · 2 comments
Open

Comments

@david-bouyssie
Copy link

I'm trying to use the following code to load a config:

    let tmp_conf: TestConfig = HoconLoader::new()
        .load_file("./tmp.conf")?
        .resolve()?;

But I get the following error: Error deserializing: ".: missing field `child2`"

Here is the config file:

title = "test"

child1 {
  home = "./dir1"
}

child2 {
  home = "./dir2"
}

Here are the defined structs:

#[derive(Clone, Deserialize)]
pub struct TestConfig {
    pub title: String,
    pub child1: Child1,
    pub child2: Child2
}

#[derive(Clone, Deserialize)]
pub struct Child1 {
    pub home: String,
}

#[derive(Clone, Deserialize)]
pub struct Child2 {
    pub home: String,
}

Important note, using from_str directly works without error:

 let s = r#"{
      title = "test"
      
      child1 {
        home = "./dir1"
      }
      
      child2 {
        home = "./dir2"
      }
    }"#;

let config: TestConfig = hocon::de::from_str(s)?;
@david-bouyssie
Copy link
Author

I forgot to say that I was testing on Windows.
It seems to be a line separator issue.

If I force Unix line separator (LF), then the error goes away.

@david-bouyssie
Copy link
Author

So a possible workaround until a fix is:

    let s = std::fs::read_to_string("./tmp.conf")?.replace('\r', "");
    let tmp_conf: TestConfig = hocon::de::from_str(&*s)?;

mockersf added a commit that referenced this issue Apr 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant