{"record":{"id":"18810fa19f5a98de","repo":"rust-lang/rust","slug":"bless-error-cannot-find-variable-var-name","errorCode":null,"errorMessage":"<bless error: Cannot find variable {var_name}>","messagePattern":"<bless error: Cannot find variable (.+?)>","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/etc/lldb_batchmode/from_lldb.py","lineNumber":326,"sourceCode":"        synthetic,\n        summary,\n        format,\n        children,\n    )\n\n\ndef bless_variable(\n    target_data: TargetData, var_name: str, breakpoint_idx: int, frame: lldb.SBFrame\n):\n    \"\"\"Updates the given `TargetData` with data generated from the given variable at the given\n    breakpoint. This function **does not** write to the input file. Please see\n    `TargetData.save_blessing` for more info on when and how to save the data.\n    \"\"\"\n\n    valobj = frame.FindVariable(var_name)\n    if not valobj.IsValid():\n        # FIXME (todo) error handling\n        raise Exception(f\"<bless error: Cannot find variable {var_name}>\")\n\n    # HACK it's obviously not ideal to output empty breakpoints, but it will be somewhat rare for it\n    # to happen (you would need a breakpoint with repr -> breakpoint without repr -> breakpoint\n    # with repr). In the more common case (e.g. 1 breakpoint, sequential breakpoints all with repr\n    # commands), this saves a lot more space than converting all TargetData.breakpoints to\n    # `dict[int,...]`\n    if len(target_data.breakpoints) <= breakpoint_idx:\n        target_data.breakpoints.extend(\n            {} for i in range(1 + breakpoint_idx - len(target_data.breakpoints))\n        )\n\n    var_data = variable_from_lldb(valobj)\n    target_data.breakpoints[breakpoint_idx][var_name] = var_data\n\n    # We also need to bless the types of the valobj's children, as they may not appear in the type\n    # or fields.\n    target = valobj.GetTarget()\n","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/src/etc/lldb_batchmode/from_lldb.py#L308-L344","documentation":"Raised by from_lldb.bless_variable when frame.FindVariable(var_name) returns an SBValue that is not valid, meaning LLDB cannot find a local/static with that name in the given frame. The message is wrapped in <bless error: ...> so the bless driver surfaces it clearly during reference generation.","triggerScenarios":"Calling bless_variable with a var_name that does not exist in frame, or exists but was optimized out so FindVariable yields an invalid SBValue. The `if not valobj.IsValid()` guard at line 324 fires.","commonSituations":"Test specifies a `lldb-check`/`lldb-var` line for a variable that no longer exists after a refactor; optimization removed the variable; the wrong breakpoint/frame was captured.","solutions":["Match the var_name in the test directive to an actual local at that breakpoint (inspect with `frame variable` in LLDB).","Recompile with -C opt-level=0 -C debuginfo=2 so the variable survives.","If the variable was removed on purpose, delete the corresponding bless/check directives."],"exampleFix":"# before: blessing a variable that no longer exists\nbless_variable(data, 'old_name', idx, frame)\n# after\nbless_variable(data, 'new_name', idx, frame)\n","handlingStrategy":"type-guard","validationCode":"valobj = frame.FindVariable(var_name)\nif not valobj.IsValid():\n    raise Exception(f\"<bless error: Cannot find variable {var_name}>\")\n","typeGuard":"def frame_has_variable(frame: lldb.SBFrame, name: str) -> bool:\n    return frame.FindVariable(name).IsValid()\n","tryCatchPattern":"try:\n    bless_variable(target_data, var_name, idx, frame)\nexcept Exception as e:\n    if \"Cannot find variable\" in str(e):\n        print(f\"variable {var_name!r} not live at breakpoint {idx}; check name/opt level\")\n        raise\n    raise\n","preventionTips":["Keep the var_name in the directive in sync with the source after refactors.","Bless at -C opt-level=0 so variables are not optimized out."],"tags":["lldb","debuginfo","blessing","rust"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}