Skip to content

Config overhaul: missing toml file location in Figment errors #855

@josecelano

Description

@josecelano

Parent issue: #401

We don't have the toml file path in Figment errors because we always pass the toml file contents to Figment:

pub fn load(info: &Info) -> Result<Configuration, Error> {
    let figment = Figment::from(Serialized::defaults(Configuration::default()))
        .merge(Toml::string(&info.tracker_toml))
        .merge(Env::prefixed("TORRUST_TRACKER__").split("__"));

    let mut config: Configuration = figment.extract()?;

    // Deprecated manual overwritting of config options
    if let Some(ref token) = info.api_admin_token {
        config.override_api_admin_token(token);
    };

    Ok(config)
}

See: #854

Since we always pass Figment the contents of the toml file it does not know the location for the original toml file. We have to change the Info struct to provide the original info, contents, or file, and let Fgment load the file if needed. I will open a new issue for this when I finish the current open PR.

Error message:

$ cargo run
    Finished `dev` profile [optimized + debuginfo] target(s) in 0.10s
     Running `target/debug/torrust-tracker`
Loading default configuration file: `./share/default/config/tracker.development.sqlite3.toml` ...
thread 'main' panicked at src/bootstrap/config.rs:45:32:
called `Result::unwrap()` on an `Err` value: ConfigError { source: LocatedError { source: Error { tag: Tag(Default, 2), profile: Some(Profile(Uncased { string: "default" })), metadata: Some(Metadata { name: "TOML source string", source: None, provide_location: Some(Location { file: "packages/configuration/src/v1/mod.rs", line: 397, col: 14 }), interpolater:  }), path: ["health_check_api", "bind_address"], kind: Message("invalid socket address syntax"), prev: None }, location: Location { file: "packages/configuration/src/v1/mod.rs", line: 400, col: 41 } } }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The error should show the file location ./share/default/config/tracker.development.sqlite3.toml.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions