NationalSecurityAgency/ghidra · error · TypeError

{node} is not {err_msg}

Error message

{node} is not {err_msg}

What it means

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.

Source

Thrown at Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/methods.py:883

@REGISTRY.method(display='Refresh Events (custom)', condition=util.dbg.IS_TRACE)
@util.dbg.eng_thread
def refresh_trace_events_custom(node: State,
                                cmd: Annotated[str, ParamDesc(display='Cmd')],
                                prefix: Annotated[str, ParamDesc(display='Prefix')] = "dx -r2 @$cursession.TTD") -> None:
    """Parse TTD objects generated from a LINQ command."""
    with commands.open_tracked_tx('Put Events (custom)'):
        commands.ghidra_trace_put_trace_events_custom(prefix, cmd)


@REGISTRY.method(action='add_handler', display='Add Handler')
def add_handler_breakpoint(node: BreakpointSpec, handler: str) -> None:
    """
    Add python handler
    """
    mat = PROC_BREAKBPT_PATTERN.fullmatch(node.path)
    if mat is None:
        raise TypeError(f"{node} is not {err_msg}")
    bptnum = int(mat['breaknum'])
    with commands.open_tracked_tx('Add Exception Handler'):
        util.BPT_HANDLERS[bptnum] = handler
        commands.ghidra_trace_put_breakpoints()


@REGISTRY.method(action='add_handler', display='Add Handler')
def add_handler_exception(node: Exception, handler: str) -> None:
    """
    Add python handler
    """
    mat = PROC_EXCEPTION_PATTERN.fullmatch(node.path)
    if mat is None:
        raise TypeError(f"{node} is not {err_msg}")
    excnum = int(mat['excnum'])
    with commands.open_tracked_tx('Add Exception Handler'):
        exc_code = util.EXC_CODES[excnum]
        util.EXC_HANDLERS[exc_code] = handler

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Confirm node.path matches PROC_BREAKBPT_PATTERN before invoking add_handler_breakpoint().
  2. Fix the latent bug: replace `err_msg` with the literal "a BreakpointSpec" so the message renders instead of NameError.
  3. Route handler-add actions through the correct node type (Breakpoint vs Exception vs Event).

Example fix

// before (methods.py:883)
if mat is None:
    raise TypeError(f"{node} is not {err_msg}")  # err_msg undefined -> NameError
// after
if mat is None:
    raise TypeError(f"{node} is not a BreakpointSpec")
Defensive patterns

Strategy: type-guard

Validate before calling

if PROC_BREAKBPT_PATTERN.fullmatch(node.path) is None:
    raise ValueError(f'not a BreakpointSpec node: {node.path}')
add_handler_breakpoint(node, handler)

Type guard

from ghidradbg.methods import PROC_BREAKBPT_PATTERN

def is_breakpoint_spec_node(obj) -> bool:
    return isinstance(obj, TraceObject) and bool(
        PROC_BREAKBPT_PATTERN.fullmatch(getattr(obj, 'path', '')))

Try / catch

try:
    add_handler_breakpoint(node, handler)
except (TypeError, NameError) as e:
    # NameError is the latent err_msg bug; guard until patched
    log.warning('add_handler_breakpoint rejected node %s: %s', getattr(node,'path',node), e)

Prevention

When it happens

Trigger: 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.

Common situations: Wiring the add_handler action to the wrong node type; schema path changes that drop the [breaknum] suffix.

Related errors


AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14). Data as JSON: /api/errors/f0b1a849ec2909db. Report an issue: GitHub.