2 Commits

Author SHA1 Message Date
247c06dd9e Rename the config-string-reading function 2025-07-17 13:32:55 -05:00
cb314a8b4c Assert empty conf str is an error, TODO: semantics
The empty configuration string is some kind of an error, but I'm not
sure where and how to handle it. It should be treated as a soft error,
where I fall back to some hardcoded defaults.

There's a logic hole at the moment: The error I'm actually getting right
now is "NoSuchTable" because the "[all]" table doesn't exist. For a
totally empty config file, the above response should be used. But what
about a non-empty conf file? Is a missing "[all]" valid or not? For now,
assert the loader returns *an* error and leave behind a TODO for later.
2025-07-17 13:29:25 -05:00

View File

@@ -71,7 +71,7 @@ struct WholeFile {
project_overrides: Vec<PartialConfig>, project_overrides: Vec<PartialConfig>,
} }
fn lconf(text: &str) -> Result<WholeFile> { fn read_conf_str(text: &str) -> Result<WholeFile> {
let mut whole = WholeFile::default(); let mut whole = WholeFile::default();
let toml_val = text.parse::<Value>()?; let toml_val = text.parse::<Value>()?;
@@ -235,11 +235,25 @@ repo = \"rcalc\"
], ],
}; };
let conf = lconf(fx_sample_config_string)?; let conf = read_conf_str(fx_sample_config_string)?;
println!(" ->> Test conf: {:?}", conf); println!(" ->> Test conf: {:?}", conf);
println!(" ->> Ref conf: {:?}", fx_expected_struct); println!(" ->> Ref conf: {:?}", fx_expected_struct);
assert_eq!(conf, fx_expected_struct); assert_eq!(conf, fx_expected_struct);
Ok(()) Ok(())
} }
/* TODO: Improve semantics around reading an empty string
An empty config string will result in Error::NoSuchTable when "[all]"
is retrieved. But this will *also* happen when other configs are present,
but "[all]" isn't. Do I treat these as valid configurations, using some
hard-coded default as the fallback? Or do I reject configs that don't have
an all-table?
*/
#[test]
fn read_config_string_empty() {
let fx_sample_cfg = "";
let conf = read_conf_str(fx_sample_cfg);
assert!(conf.is_err());
}
} }