{"record":{"id":"b75fcf265d85667b","repo":"NationalSecurityAgency/ghidra","slug":"invalid-argument-key-list-0-b75fcf","errorCode":null,"errorMessage":"Invalid argument: {key_list[0]}","messagePattern":"Invalid argument: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger-agent-x64dbg/src/main/py/src/ghidraxdbg/commands.py","lineNumber":754,"sourceCode":"    switch, then the switch is required. Only the first argument is taken as the\n    switch. All others are taken as keys.\n    \"\"\"\n\n    key_list = keys.split(\" \")\n\n    trace, tx = STATE.require_tx()\n    kinds = 'elements'\n    if key_list[0] == '--elements':\n        kinds = 'elements'\n        key_list = key_list[1:]\n    elif key_list[0] == '--attributes':\n        kinds = 'attributes'\n        key_list = key_list[1:]\n    elif key_list[0] == '--both':\n        kinds = 'both'\n        key_list = key_list[1:]\n    elif key_list[0].startswith('--'):\n        raise RuntimeError(\"Invalid argument: \" + key_list[0])\n    trace.proxy_object_path(path).retain_values(key_list, kinds=kinds)\n\n\ndef ghidra_trace_get_obj(path: str) -> None:\n    \"\"\"Get an object descriptor by its canonical path.\n\n    This isn't the most informative, but it will at least confirm\n    whether an object exists and provide its id.\n    \"\"\"\n\n    trace = STATE.require_trace()\n    object = trace.get_object(path)\n    print(f\"{object.id}\\t{object.path}\")\n\n\ndef ghidra_trace_get_values(pattern: str) -> None:\n    \"\"\"List all values matching a given path pattern.\"\"\"\n","sourceCodeStart":736,"sourceCodeEnd":772,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger-agent-x64dbg/src/main/py/src/ghidraxdbg/commands.py#L736-L772","documentation":"Raised by ghidra_trace_retain_values (commands.py:753-754) when the first token of the keys argument starts with '--' but is not one of the recognized switches (--elements, --attributes, --both). The command splits keys on spaces and inspects only key_list[0] for a switch; an unknown switch is rejected before retain_values is called.","triggerScenarios":"Calling the retain-values command with an unrecognized leading switch, e.g. keys='--all [0] [1]' or '--elems'. The first token begins with '--' and matches no case.","commonSituations":"Typing a switch name from memory (--all, --values) that does not exist; an older/newer agent version with different switch names; a script that interpolates an unintended '--' prefix into the keys.","solutions":["Use one of the valid switches: --elements, --attributes, --both, or omit the switch entirely (defaults to elements).","If a key legitimately starts with '--', you must still pass a valid switch first (the docstring notes the switch is required in that case).","Check for typos in the switch name against the command docstring."],"exampleFix":"// before\nghidra_trace_retain_values(path, '--all [0] [1]')\n\n// after\nghidra_trace_retain_values(path, '--both [0] [1]')","handlingStrategy":"validation","validationCode":"VALID_SWITCHES = {'--elements', '--attributes', '--both'}\ndef retain(path, keys):\n    first = keys.split(' ', 1)[0]\n    if first.startswith('--') and first not in VALID_SWITCHES:\n        raise ValueError(f'Unknown switch {first}; valid: {sorted(VALID_SWITCHES)}')\n    ghidra_trace_retain_values(path, keys)","typeGuard":"def switch_is_valid(keys: str) -> bool:\n    first = keys.split(' ', 1)[0]\n    return not first.startswith('--') or first in {'--elements', '--attributes', '--both'}","tryCatchPattern":"try:\n    ghidra_trace_retain_values(path, keys)\nexcept RuntimeError as e:\n    if 'Invalid argument' in str(e):\n        # drop the bad switch and retry with default (elements)\n        ghidra_trace_retain_values(path, keys.split(' ', 1)[1] if ' ' in keys else '')\n    else:\n        raise","preventionTips":["Restrict switch input to the three documented values.","If a key legitimately starts with '--', pass a valid switch first.","Validate the first token before dispatching the command."],"tags":["argument-validation","retain-values","trace-agent","python"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}