Skip to content

fix(stt): filter None values in config.save() to fix silent TOML serialization failure#5

Open
Kyotani-Hub wants to merge 1 commit into
elevenlabs:mainfrom
Kyotani-Hub:fix/stt-config-save-none-serialization
Open

fix(stt): filter None values in config.save() to fix silent TOML serialization failure#5
Kyotani-Hub wants to merge 1 commit into
elevenlabs:mainfrom
Kyotani-Hub:fix/stt-config-save-none-serialization

Conversation

@Kyotani-Hub
Copy link
Copy Markdown

Summary

Config.save() silently fails (returns False) for every user with default settings because the input_device field defaults to None, and TOML has no null type.

When tomli_w.dump() encounters None in the data dict, it raises a TypeError. This exception is swallowed by the bare except Exception: return False block, so the failure is completely silent — no config file is ever written after a fresh install.

Root Cause

In stt/src/elevenlabs_stt/config.py, the save() method constructs the TOML data dict with all fields unconditionally:

data = {
    "elevenlabs-stt": {
        ...
        "input_device": self.input_device,  # None by default
        ...
    }
}

tomli_w faithfully follows the TOML spec, which has no null/None type, so dump() raises TypeError.

Fix

Filter out None values before passing the dict to tomli_w.dump():

fields = {
    "api_key": self.api_key,
    ...
    "input_device": self.input_device,
    ...
}
data = {"elevenlabs-stt": {k: v for k, v in fields.items() if v is not None}}

When input_device is explicitly set to a device name (a string), it is included normally. When it is None (the default), it is simply omitted from the TOML file — and load() already handles missing keys correctly by using the Pydantic field defaults.

Test plan

  • Fresh install: Config().save() returns True and writes a valid config.toml
  • With input_device set to a string: field appears in saved TOML
  • With input_device as None (default): field is omitted, load() still returns input_device=None
  • Round-trip: save() then load() preserves all non-None settings

Fixes #3

…zation error

The `input_device` field defaults to `None`, but TOML has no null type.
`tomli_w.dump()` raises `TypeError` on `None` values, which was caught
by a bare `except Exception: return False`, making `save()` silently
fail for all users with default settings.

Fixes elevenlabs#3
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

Successfully merging this pull request may close these issues.

STT config.save() silently fails due to None value in TOML serialization

1 participant