{"record":{"id":"dc52b7ae6870a56a","repo":"nautechsystems/nautilus_trader","slug":"theme-name-cannot-be-empty","errorCode":null,"errorMessage":"Theme name cannot be empty","messagePattern":"Theme name cannot be empty","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/nautilus_trader/analysis/themes.py","lineNumber":173,"sourceCode":"    ...     \"custom\",\n    ...     \"plotly_white\",\n    ...     {\n    ...         \"primary\": \"#ff6600\",\n    ...         \"positive\": \"#00ff00\",\n    ...         \"negative\": \"#ff0000\",\n    ...         \"neutral\": \"#808080\",\n    ...         \"background\": \"#ffffff\",\n    ...         \"grid\": \"#dddddd\",\n    ...     },\n    ... )\n\n    \"\"\"\n    _require_not_none(name, \"name\")\n    _require_not_none(template, \"template\")\n    _require_not_none(colors, \"colors\")\n\n    if not name.strip():\n        raise ValueError(\"Theme name cannot be empty\")\n\n    required_keys = {\"primary\", \"positive\", \"negative\", \"neutral\", \"background\", \"grid\"}\n    missing_keys = required_keys - set(colors.keys())\n    if missing_keys:\n        raise ValueError(\n            f\"Colors dict missing required keys: {missing_keys}. Required keys: {required_keys}\",\n        )\n\n    _THEMES[name] = {\n        \"template\": template,\n        \"colors\": colors.copy(),\n    }\n\n\ndef list_themes() -> list[str]:\n    \"\"\"\n    List all registered theme names.\n","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/python/nautilus_trader/analysis/themes.py#L155-L191","documentation":"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.","triggerScenarios":"register_theme(name=\"\", template=..., colors=...) or whitespace-only names, typically from unparsed/blank config values.","commonSituations":"Theme names read from environment variables or config files that are empty; template strings where the placeholder was not substituted.","solutions":["Pass a non-empty theme name","Strip and validate the name at the call site before registering","Fall back to a default name when the configured value is blank"],"exampleFix":"// before\nname = os.environ.get(\"NT_THEME\", \"\")  # \"\"\nregister_theme(name, template, colors)  # ValueError\n// after\nname = os.environ.get(\"NT_THEME\", \"custom-dark\")\nregister_theme(name, template, colors)","handlingStrategy":"validation","validationCode":"name = (name or \"\").strip()\nif not name:\n    name = \"custom-default\"\nregister_theme(name, template, colors)","typeGuard":null,"tryCatchPattern":"try:\n    register_theme(name, template, colors)\nexcept ValueError as e:\n    if \"cannot be empty\" in str(e):\n        register_theme(\"custom-default\", template, colors)\n    else:\n        raise","preventionTips":["Strip and default theme names read from env/config before registering","Reject blank theme names during config parsing, earlier in the pipeline","Use fixed literal names for programmatic theme registration"],"tags":["python","validation","valueerror","theme","registry"],"backgroundTag":"empty-required-field","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}