{"record":{"id":"ab98b5d78db3a0a8","repo":"OpenBB-finance/OpenBB","slug":"label-must-be-specified","errorCode":null,"errorMessage":"Label must be specified","messagePattern":"Label must be specified","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openbb_platform/obbject_extensions/charting/openbb_charting/core/openbb_figure.py","lineNumber":801,"sourceCode":"            If label is not specified and trace is not specified\n        \"\"\"\n        if trace:\n            for trace_ in self.data:\n                if trace_.name == trace:  # type: ignore\n                    for arg, default in zip(\n                        [label, mode, marker, line_dash],\n                        [trace, trace_.mode, trace_.marker, trace_.line_dash],  # type: ignore\n                    ):\n                        if not arg and default:\n                            arg = default  # noqa: PLW2901\n\n                    kwargs.update(dict(yaxis=trace_.yaxis))  # type: ignore\n                    break\n            else:\n                raise ValueError(f\"Trace '{trace}' not found\")\n\n        if not label:\n            raise ValueError(\"Label must be specified\")\n\n        self.add_scatter(\n            x=[None],\n            y=[None],\n            mode=mode or \"lines\",\n            name=label,\n            marker=marker or dict(),\n            line_dash=line_dash or \"solid\",\n            legendrank=legendrank,\n            **kwargs,\n        )\n\n    def show(  # noqa: PLR0915\n        self,\n        *args,\n        external: bool = False,\n        export_image: Path | str | None = \"\",  # pylint: disable=W0613\n        **kwargs,","sourceCodeStart":783,"sourceCodeEnd":819,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/obbject_extensions/charting/openbb_charting/core/openbb_figure.py#L783-L819","documentation":"In OpenBBFigure.add_legend_label (openbb_figure.py:801), after the trace-lookup block the method requires a truthy `label` — the visible text of the dummy scatter it adds to build the legend entry. An empty/None label makes the legend entry invisible and meaningless, so it raises ValueError(\"Label must be specified\").","triggerScenarios":"Calling add_legend_label() with no arguments, or with label=\"\"/None — including code that reads the label from a config key that is absent and defaults to None.","commonSituations":"Programmatic loops over indicator configs where some entries lack a label field; refactors that renamed the parameter (e.g. text->label) leaving the old call shape.","solutions":["Pass a non-empty label: fig.add_legend_label(label=\"200D MA\").","Default it from config: label = cfg.get(\"label\") or \"unnamed series\".","Skip the call entirely when no label is available — a legend entry without text serves no purpose."],"exampleFix":"# before\nfig.add_legend_label(trace=\"sma\", label=cfg.get(\"text\"))  # None -> ValueError\n\n# after\nlabel = cfg.get(\"text\") or cfg.get(\"label\")\nif label:\n    fig.add_legend_label(trace=\"sma\", label=label)","handlingStrategy":"validation","validationCode":"label = label or cfg.get(\"text\") or \"\"\nif label:\n    fig.add_legend_label(trace=trace, label=label)","typeGuard":"def valid_legend_label(label) -> bool:\n    return isinstance(label, str) and bool(label.strip())","tryCatchPattern":"try:\n    fig.add_legend_label(trace=trace, label=label)\nexcept ValueError as e:\n    if \"Label must be specified\" in str(e):\n        pass  # nothing to show\n    else:\n        raise","preventionTips":["Default label strings in config-driven loops: entry.get(\"label\") or \"unnamed\".","Skip the call when no text is available.","Watch for parameter renames (text vs label) when copying examples."],"tags":["python","openbb","charting","validation","plotly"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}