nautechsystems/nautilus_trader · error · ValueError

Theme name cannot be empty

Error message

Theme name cannot be empty

What it means

register_theme validates arguments before storing a theme: after requiring name/template/colors to be non-None, it rejects a name that is empty after .strip() so the theme registry never contains blank keys.

Solutions

  1. Pass a non-empty theme name
  2. Strip and validate the name at the call site before registering
  3. Fall back to a default name when the configured value is blank

Example fix

// before
name = os.environ.get("NT_THEME", "")  # ""
register_theme(name, template, colors)  # ValueError
// after
name = os.environ.get("NT_THEME", "custom-dark")
register_theme(name, template, colors)
Defensive patterns

Strategy: validation

Validate before calling

name = (name or "").strip()
if not name:
    name = "custom-default"
register_theme(name, template, colors)

Try / catch

try:
    register_theme(name, template, colors)
except ValueError as e:
    if "cannot be empty" in str(e):
        register_theme("custom-default", template, colors)
    else:
        raise

Prevention

When it happens

Trigger: register_theme(name="", template=..., colors=...) or whitespace-only names, typically from unparsed/blank config values.

Common situations: Theme names read from environment variables or config files that are empty; template strings where the placeholder was not substituted.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/dc52b7ae6870a56a. Report an issue: GitHub.

Appendix: source

Thrown at python/nautilus_trader/analysis/themes.py:173

    ...     "custom",
    ...     "plotly_white",
    ...     {
    ...         "primary": "#ff6600",
    ...         "positive": "#00ff00",
    ...         "negative": "#ff0000",
    ...         "neutral": "#808080",
    ...         "background": "#ffffff",
    ...         "grid": "#dddddd",
    ...     },
    ... )

    """
    _require_not_none(name, "name")
    _require_not_none(template, "template")
    _require_not_none(colors, "colors")

    if not name.strip():
        raise ValueError("Theme name cannot be empty")

    required_keys = {"primary", "positive", "negative", "neutral", "background", "grid"}
    missing_keys = required_keys - set(colors.keys())
    if missing_keys:
        raise ValueError(
            f"Colors dict missing required keys: {missing_keys}. Required keys: {required_keys}",
        )

    _THEMES[name] = {
        "template": template,
        "colors": colors.copy(),
    }


def list_themes() -> list[str]:
    """
    List all registered theme names.

View on GitHub (pinned to 18893faf8b)