Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SamPeng87 opened this issue Nov 7, 2024 · 1 comment

Comments

@SamPeng87
Copy link

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.

@SamPeng87
Copy link
Author

may be,I need use merge interface?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant