Skip to content

Typo'd config keys are silently ignored — surface them via MetaData.Undecoded() #24

Description

@jason-shen

Problem

config.Load throws away the decoder metadata:

// internal/config/config.go
if _, err := toml.DecodeFile(path, cfg); err != nil {
	return nil, fmt.Errorf("failed to parse %s: %w", path, err)
}

toml.DecodeFile returns a MetaData whose Undecoded() method lists every key present in the file that did not map to a struct field. Discarding it means a misspelled or misplaced key is silently ignored — the file parses fine and the server starts with a default the operator did not choose.

This fails in a genuinely confusing way. Write api_ke instead of api_key under [cartesia] and you get [cartesia] api_key missing at startup while staring at a config file that visibly contains an api key. Put barge_in at the top level instead of under [pipeline] and barge-in silently stays at its default with no complaint at all. Config here is the entire operator interface — nearly every knob (provider selection, endpointing, barge-in timing, TURN credentials) is a TOML key, so a typo class that fails silently is expensive.

Proposed change

Capture the metadata and report unknown keys.

md, err := toml.DecodeFile(path, cfg)
if err != nil {
	return nil, fmt.Errorf("failed to parse %s: %w", path, err)
}
if undecoded := md.Undecoded(); len(undecoded) > 0 {
	// join keys with ", " and surface them
}

Warn or fail? Suggest warning by default via log.Printf — hard-failing could break a running deployment on upgrade if someone is carrying a key we later remove. A follow-up could add --strict-config to turn it into an error. Open to the opposite call from a maintainer; say so on the issue before starting if you prefer a hard error.

One wrinkle worth handling: keys under [plugins] and any provider section the build doesn't know about should still be reported, but the message should read as advice ("unknown key ... — check for a typo"), not as an error.

Acceptance criteria

  • A config containing api_ke = "x" under a provider section produces a message naming cartesia.api_ke.
  • A config with only valid keys logs nothing new.
  • Test in internal/config/config_test.go that writes a temp TOML file with a bogus key and asserts the key is reported.

Pointers

  • internal/config/config.goLoad(), ~L286
  • github.com/BurntSushi/tomlMetaData.Undecoded() returns []Key; Key.String() gives the dotted path

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgood first issueScoped small, with enough context in the issue to start

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions