nautechsystems/nautilus_trader · error · ValueError

{name} must not be None

Error message

{name} must not be None

What it means

themes._require_not_none is the module's null guard, used by get_theme and register_theme to refuse None for name/template/colors arguments. It converts a would-be confusing downstream TypeError ('argument of type NoneType') into an explicit '<param> must not be None' ValueError at the API boundary.

Source

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

        "colors": {
            "primary": "#00cfbe",
            "positive": "#2fadd7",
            "negative": "#ff6b6b",
            "neutral": "#a7aab5",
            "background": "#2a2a2d",
            "grid": "#202022",
            "table_section": "#35353a",
            "table_row_odd": "#2a2a2d",
            "table_row_even": "#242428",
            "table_text": "#eeeeee",
        },
    },
}


def _require_not_none(value: Any, name: str) -> None:
    if value is None:
        raise ValueError(f"{name} must not be None")


def get_theme(name: str) -> dict[str, Any]:
    """
    Get theme configuration by name.

    Parameters
    ----------
    name : str
        The theme name. Built-in themes: "plotly_white", "plotly_dark", "nautilus", "nautilus_dark".

    Returns
    -------
    dict[str, Any]
        Theme configuration dictionary with "template" and "colors" keys.

    Raises
    ------

View on GitHub (pinned to a4b06ed870)

Solutions

  1. Pass an explicit theme name, e.g. get_theme('nautilus_dark')
  2. Default the value at the call site: theme = theme or 'plotly_white' before calling
  3. Check required inputs when building configs from external sources (YAML/CLI)

Example fix

# before
get_theme(cfg.get('theme'))  # cfg['theme'] missing -> None
# ValueError: name must not be None

# after
get_theme(cfg.get('theme') or 'plotly_white')
Defensive patterns

Strategy: validation

Validate before calling

if theme_name is None:
    theme_name = 'plotly_white'
theme = get_theme(theme_name)

Type guard

def is_theme_name(value: object) -> bool:
    return isinstance(value, str) and bool(value)

Try / catch

try:
    theme = get_theme(name)
except ValueError as e:
    if 'must not be None' in str(e):
        theme = get_theme('plotly_white')
    else:
        raise

Prevention

When it happens

Trigger: Calling get_theme(None) (e.g. theme name read from a config that defaulted to None), or register_theme(None, template, colors) / register_theme(name, None, colors) / register_theme(name, template, None).

Common situations: TearsheetConfig built programmatically where theme was never set; passing an optional config field straight through without a default; refactors that changed a required arg to None-able.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@a4b06ed870 (2026-08-16). Data as JSON: /api/errors/662559ca9bb6267c. Report an issue: GitHub.