{"record":{"id":"5ed02c70bbed4d85","repo":"NationalSecurityAgency/ghidra","slug":"invalid-argument-key-list-0","errorCode":null,"errorMessage":"Invalid argument: {key_list[0]}","messagePattern":"Invalid argument: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/commands.py","lineNumber":855,"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":837,"sourceCodeEnd":873,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/commands.py#L837-L873","documentation":"Raised by ghidra_trace_retain_values() (commands.py:854-855) when the first token of the keys string starts with '--' but is not one of the recognized switches (--elements, --attributes, --both). The command accepts an optional leading switch to scope the retain operation; any other dash-prefixed token is rejected as an invalid argument.","triggerScenarios":"Calling ghidra_trace_retain_values(path, '--element key1') (typo, missing 's'); passing '--all' or any unsupported flag; passing a key name that legitimately starts with '--' without first emitting the required switch (the docstring notes the switch is then required to disambiguate).","commonSituations":"Typo in the switch name; key name colliding with the switch prefix; copy/paste from a different command's flag vocabulary.","solutions":["Use exactly one of --elements, --attributes, --both as the optional first token, or omit the switch entirely.","If a real key starts with '--', you must prefix the call with an explicit valid switch (e.g. '--elements --mykey').","Check spelling: it is --attributes (plural), --elements (plural), --both."],"exampleFix":"// before\nghidra_trace_retain_values('Processes[0]', '--element a b')   # typo\n\n// after\nghidra_trace_retain_values('Processes[0]', '--elements a b')\n# or omit the switch:\nghidra_trace_retain_values('Processes[0]', 'a b')\n# if a key literally starts with '--', force the switch:\nghidra_trace_retain_values('Processes[0]', '--both --mykey otherkey')","handlingStrategy":"validation","validationCode":"VALID_SWITCHES = {'--elements', '--attributes', '--both'}\ndef normalize_retain_keys(keys):\n    tokens = keys.split()\n    if tokens and tokens[0].startswith('--'):\n        if tokens[0] not in VALID_SWITCHES:\n            raise ValueError(f'invalid switch {tokens[0]!r}; use one of {VALID_SWITCHES}')\n    return keys\n\nghidra_trace_retain_values(path, normalize_retain_keys(keys))","typeGuard":"def retain_keys_well_formed(keys) -> bool:\n    tokens = keys.split()\n    if not tokens:\n        return True\n    if tokens[0].startswith('--'):\n        return tokens[0] in {'--elements', '--attributes', '--both'}\n    return True","tryCatchPattern":"try:\n    ghidra_trace_retain_values(path, keys)\nexcept RuntimeError as e:\n    if 'Invalid argument' in str(e):\n        # drop the bogus switch and retry, or prompt user\n        keys = ' '.join(t for t in keys.split() if not t.startswith('--'))\n        ghidra_trace_retain_values(path, keys)\n    else:\n        raise","preventionTips":["Spell switches exactly: --elements, --attributes, --both.","If a key starts with '--', prefix the call with an explicit valid switch.","Validate the first token in your wrapper before forwarding."],"tags":["usage","argument-parsing","trace-lifecycle","ghidra"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}