{"record":{"id":"f0b1a849ec2909db","repo":"NationalSecurityAgency/ghidra","slug":"node-is-not-err-msg","errorCode":null,"errorMessage":"{node} is not {err_msg}","messagePattern":"(.+?) is not (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/methods.py","lineNumber":883,"sourceCode":"\n@REGISTRY.method(display='Refresh Events (custom)', condition=util.dbg.IS_TRACE)\n@util.dbg.eng_thread\ndef refresh_trace_events_custom(node: State,\n                                cmd: Annotated[str, ParamDesc(display='Cmd')],\n                                prefix: Annotated[str, ParamDesc(display='Prefix')] = \"dx -r2 @$cursession.TTD\") -> None:\n    \"\"\"Parse TTD objects generated from a LINQ command.\"\"\"\n    with commands.open_tracked_tx('Put Events (custom)'):\n        commands.ghidra_trace_put_trace_events_custom(prefix, cmd)\n\n\n@REGISTRY.method(action='add_handler', display='Add Handler')\ndef add_handler_breakpoint(node: BreakpointSpec, handler: str) -> None:\n    \"\"\"\n    Add python handler\n    \"\"\"\n    mat = PROC_BREAKBPT_PATTERN.fullmatch(node.path)\n    if mat is None:\n        raise TypeError(f\"{node} is not {err_msg}\")\n    bptnum = int(mat['breaknum'])\n    with commands.open_tracked_tx('Add Exception Handler'):\n        util.BPT_HANDLERS[bptnum] = handler\n        commands.ghidra_trace_put_breakpoints()\n\n\n@REGISTRY.method(action='add_handler', display='Add Handler')\ndef add_handler_exception(node: Exception, handler: str) -> None:\n    \"\"\"\n    Add python handler\n    \"\"\"\n    mat = PROC_EXCEPTION_PATTERN.fullmatch(node.path)\n    if mat is None:\n        raise TypeError(f\"{node} is not {err_msg}\")\n    excnum = int(mat['excnum'])\n    with commands.open_tracked_tx('Add Exception Handler'):\n        exc_code = util.EXC_CODES[excnum]\n        util.EXC_HANDLERS[exc_code] = handler","sourceCodeStart":865,"sourceCodeEnd":901,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/methods.py#L865-L901","documentation":"Raised as TypeError by add_handler_breakpoint() when node.path does not full-match PROC_BREAKBPT_PATTERN, i.e. the object is not a BreakpointSpec node. NOTE: the format string references an undefined name `err_msg` (it is not a parameter of this function), so in practice the raise would itself throw NameError — the documented message is the intended one and the missing literal is a latent bug.","triggerScenarios":"Invoking the 'add_handler' action on a node whose path is not 'Processes[...].Breakpoints[<breaknum>]'; dispatching the breakpoint-handler method against an Exception or Event node.","commonSituations":"Wiring the add_handler action to the wrong node type; schema path changes that drop the [breaknum] suffix.","solutions":["Confirm node.path matches PROC_BREAKBPT_PATTERN before invoking add_handler_breakpoint().","Fix the latent bug: replace `err_msg` with the literal \"a BreakpointSpec\" so the message renders instead of NameError.","Route handler-add actions through the correct node type (Breakpoint vs Exception vs Event)."],"exampleFix":"// before (methods.py:883)\nif mat is None:\n    raise TypeError(f\"{node} is not {err_msg}\")  # err_msg undefined -> NameError\n// after\nif mat is None:\n    raise TypeError(f\"{node} is not a BreakpointSpec\")","handlingStrategy":"type-guard","validationCode":"if PROC_BREAKBPT_PATTERN.fullmatch(node.path) is None:\n    raise ValueError(f'not a BreakpointSpec node: {node.path}')\nadd_handler_breakpoint(node, handler)","typeGuard":"from ghidradbg.methods import PROC_BREAKBPT_PATTERN\n\ndef is_breakpoint_spec_node(obj) -> bool:\n    return isinstance(obj, TraceObject) and bool(\n        PROC_BREAKBPT_PATTERN.fullmatch(getattr(obj, 'path', '')))","tryCatchPattern":"try:\n    add_handler_breakpoint(node, handler)\nexcept (TypeError, NameError) as e:\n    # NameError is the latent err_msg bug; guard until patched\n    log.warning('add_handler_breakpoint rejected node %s: %s', getattr(node,'path',node), e)","preventionTips":["Patch methods.py:883 to use the literal 'a BreakpointSpec' instead of the undefined err_msg.","Validate node.path against PROC_BREAKBPT_PATTERN before invoking add_handler_breakpoint.","Only dispatch the breakpoint add_handler action against BreakpointSpec nodes."],"tags":["dbgeng","breakpoint","handler","type-mismatch","latent-bug"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}