rust-cli / rust-cli/config-rs

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

Open
#604 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
3.2k
Forks
265
Avg merge
2h 42m
Merged PRs (30d)
4

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing Config::builder(), add_source, and build() to see how source errors are collected and exposed through ConfigError. Review existing tests for layered sources and failures, then determine what behavior and API would be needed for earlier sources to remain usable when a later source fails.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.