{"record":{"id":"c90c68eeabe1f01e","repo":"OpenBB-finance/OpenBB","slug":"trace-trace-not-found","errorCode":null,"errorMessage":"Trace '{trace}' not found","messagePattern":"Trace '(.+?)' not found","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openbb_platform/obbject_extensions/charting/openbb_charting/core/openbb_figure.py","lineNumber":798,"sourceCode":"        ValueError\n            If trace is not found\n        ValueError\n            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,","sourceCodeStart":780,"sourceCodeEnd":816,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/obbject_extensions/charting/openbb_charting/core/openbb_figure.py#L780-L816","documentation":"In OpenBBFigure.add_legend_label (openbb_figure.py:798), when a `trace` name is supplied the method iterates self.data looking for a trace whose .name matches; if the for-loop completes without a break, the else-branch raises `ValueError(f\"Trace '{trace}' not found\")`. The label would have inherited the target trace's mode/marker/yaxis, so an unknown name cannot be attached.","triggerScenarios":"Calling fig.add_legend_label(trace=\"AAPL Close\", label=\"...\") when no trace in fig.data has name exactly \"AAPL Close\" — wrong casing, renamed traces, or calling before the scatter was added.","commonSituations":"Trace names built dynamically (symbol + column concatenation) that drift from what was plotted; calling add_legend_label on a fresh figure before add_scatter; traces whose name is None (unnamed) so the equality never holds.","solutions":["List existing names and use one verbatim: print([t.name for t in fig.data]).","Ensure the target scatter exists first — call add_scatter/add_candle before add_legend_label.","If you don't need style inheritance, call add_legend_label(label=\"...\") without `trace` (label alone is valid).","Guard the call: if trace not in {t.name for t in fig.data}: skip or log."],"exampleFix":"# before\nfig.add_legend_label(trace=\"close\", label=\"Support\")  # ValueError: Trace 'close' not found\n\n# after\nnames = [t.name for t in fig.data]\nif \"close\" in names:\n    fig.add_legend_label(trace=\"close\", label=\"Support\")\nelse:\n    fig.add_legend_label(label=\"Support\")","handlingStrategy":"validation","validationCode":"trace_names = {t.name for t in fig.data if t.name}\nif trace not in trace_names:\n    print(f\"available traces: {sorted(trace_names)}\")\nelse:\n    fig.add_legend_label(trace=trace, label=\"Support\")","typeGuard":"def trace_exists(fig, name: str) -> bool:\n    return any(t.name == name for t in fig.data)","tryCatchPattern":"try:\n    fig.add_legend_label(trace=name, label=text)\nexcept ValueError as e:\n    if \"not found\" in str(e):\n        logger.warning(\"skipping legend label for missing trace %s\", name)\n    else:\n        raise","preventionTips":["Derive trace names from the same constant/format used when adding the scatter.","Call add_legend_label only after all data traces are added.","Remember matching is exact and case-sensitive on trace.name."],"tags":["python","openbb","charting","plotly","validation"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}