x52dev / x52dev/confik

Tagged enums require tag set in both TOML and Env sources

Open
#118 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug-upstream
Dominant language
Rust
Stars
46
Forks
3
Avg merge
2h 57m
Merged PRs (30d)
10

Description

Say you have a serde tagged enum by #[confik(forward_serde(tag = "type"))] in the configuration:

use confik::Configuration;

#[derive(Debug, Clone, Configuration)]
#[confik(forward_serde(tag = "type", rename_all = "snake_case"))]
enum Config {
    Foo(Foo),
    Bar(Bar),
}

#[derive(Debug, Clone, Configuration)]
struct Foo {
    foo: String,
}

#[derive(Debug, Clone, Configuration)]
struct Bar {
    bar: String,
}

fn main() {
    let config = Config::builder()
        .override_with(confik::FileSource::new("config.toml"))
        .override_with(confik::EnvSource::new().allow_secrets())
        .try_build()
        .unwrap();
}

with config.toml

type = "foo"
foo = "hello"

and environment variable

TYPE=foo

The above works.
However, remove either of type = "foo" from config.toml or TYPE=foo from the environment, and this fails with an error:

(...)
missing field `type`
(...)

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 reproducing the example with Config::builder(), FileSource, and EnvSource, testing each source with and without the tagged enum's type field. Then trace how tagged enums are merged across sources. Done means a configuration can obtain the tag from either TOML or environment input without producing a missing field type error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.