index : static-web-server.git

ascending towards madness

author Jose Quintana <joseluisquintana20@gmail.com> 2023-02-04 21:11:29.0 +00:00:00
committer Jose Quintana <joseluisquintana20@gmail.com> 2023-02-04 21:11:29.0 +00:00:00
commit
2cf9008cb89d68084b47255f9850f8fc0e2b42b3 [patch]
tree
351c533b981133f3391415615e82add8d7004cbb
parent
495f3ae7576447fd0dfd3862a2d3b618321772e7
download
2cf9008cb89d68084b47255f9850f8fc0e2b42b3.tar.gz

refactor: remove toml incompatibility hacks



Diff

 src/settings/file.rs | 28 +++-------------------------
 1 file changed, 3 insertions(+), 25 deletions(-)

diff --git a/src/settings/file.rs b/src/settings/file.rs
index 682573a..1418e8f 100644
--- a/src/settings/file.rs
+++ b/src/settings/file.rs
@@ -189,29 +189,7 @@ fn read_toml_file(path: &Path) -> Result<toml::Value> {
            path.display()
        )
    })?;

    let first_error = match toml_str.parse() {
        Ok(res) => return Ok(res),
        Err(err) => err,
    };

    let mut second_parser = toml::de::Deserializer::new(&toml_str);
    second_parser.set_require_newline_after_table(false);
    if let Ok(res) = toml::Value::deserialize(&mut second_parser) {
        let msg = format!(
            "\
TOML file found which contains invalid syntax and will soon not parse
at `{}`.
The TOML spec requires newlines after table definitions (e.g., `[a] b = 1` is
invalid), but this file has a table header which does not have a newline after
it. A newline needs to be added and this warning will soon become a hard error
in the future.",
            path.display()
        );
        println!("{}", &msg);
        return Ok(res);
    }

    let first_error = anyhow::Error::from(first_error);
    Err(first_error.context("could not parse data input as toml format"))
    toml_str
        .parse()
        .map_err(|e| anyhow::Error::from(e).context("could not parse input as TOML"))
}