Skip to content

If I add multiple sources, but one of them fails. Does the whole parse fail? #604

@SamPeng87

Description

@SamPeng87

If I add 2-3 sources like code.

        let config = Config::builder()
            .add_source(File::from_str(CONFIG_DATA, config::FileFormat::Toml))//source1
            .add_source(  //source2
                config::Environment::with_prefix(APP_NAME.to_uppercase().as_str())
                    .try_parsing(true)
                    .separator("_")
                    .list_separator(","),
            );
        let res = config.add_source(File::with_name(config_path.to_str().expect("Failed to convert path to string")))source3
            .build()
            .map_err(|e| {
                error!("Failed to load config: {:?}", e);
                e
            });

This code, which returns ConfigError。so,I can't try_deserialize

My expectation is that because add_source is added sequentially, the parsing before a layer fails will still work. This way it won't be possible for one misconfiguration to cause the whole application to fall back to the default configuration on startup, which can cause huge failures. Still, config-rs does not deal with this problem, and it is up to the user to fall back on the importance if necessary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions