{"record":{"id":"28807593c8d68a16","repo":"NationalSecurityAgency/ghidra","slug":"invalid-argument-arg","errorCode":null,"errorMessage":"Invalid argument: {arg}","messagePattern":"Invalid argument: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger-agent-drgn/src/main/py/src/ghidradrgn/commands.py","lineNumber":839,"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 keys[0] == '--attributes':\n        kinds = 'attributes'\n        key_list = key_list[1:]\n    elif keys[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    \"\"\"\n    Get an object descriptor by its canonical path.\n\n    This isn't the most informative, but it will at least confirm whether an\n    object exists and provide its id.\n    \"\"\"\n\n    trace = STATE.require_trace()\n    object = trace.get_object(path)\n    print(\"{}\\t{}\".format(object.id, object.path))\n\n\ndef ghidra_trace_get_values(pattern: str) -> None:\n    \"\"\"","sourceCodeStart":821,"sourceCodeEnd":857,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger-agent-drgn/src/main/py/src/ghidradrgn/commands.py#L821-L857","documentation":"Thrown by the retain_values command handler in the drgn agent when the first element of key_list starts with '--' but is not one of the recognized flags (--elements, --attributes, --both). NOTE: the code has a latent inconsistency — it checks key_list[0] in the first and last branch but keys[0] in the middle two branches, suggesting keys and key_list may diverge in some code paths, potentially masking valid flags.","triggerScenarios":"Calling the retain_values command with an unrecognized flag like '--all', '--keys', or '--merge'. Also, if keys and key_list are different objects (due to the code bug), a valid '--attributes' or '--both' flag checked against keys[0] might fall through to the error branch if key_list[0] has already been modified.","commonSituations":"Misspelling a flag (e.g. '--atributes'); using a flag from a different version of the API; the keys/key_list variable inconsistency causing unexpected routing to the error branch.","solutions":["Use only recognized flags: --elements, --attributes, or --both.","Omit the flag entirely to default to 'elements'.","If the error persists with a correct flag, inspect the keys vs key_list variables in the source — there is a bug where --attributes and --both check keys[0] instead of key_list[0]."],"exampleFix":"// before\nghidra_trace_retain_values('Processes[]', '--all', 'key1', 'key2')\n// after\nghidra_trace_retain_values('Processes[]', '--both', 'key1', 'key2')","handlingStrategy":"validation","validationCode":"VALID_FLAGS = {'--elements', '--attributes', '--both'}\n\ndef validate_retain_args(key_list):\n    if key_list and key_list[0].startswith('--'):\n        if key_list[0] not in VALID_FLAGS:\n            raise ValueError(\n                f\"Unrecognized flag '{key_list[0]}'. Valid: {VALID_FLAGS}\")\n        return key_list[1:], key_list[0]\n    return key_list, '--elements'","typeGuard":null,"tryCatchPattern":"try:\n    ghidra_trace_retain_values(path, *args)\nexcept RuntimeError as e:\n    if 'Invalid argument' in str(e):\n        print(f\"Use --elements, --attributes, or --both. Got: {e}\")\n    raise","preventionTips":["Only use --elements, --attributes, or --both as flags.","Omit the flag entirely to default to 'elements'.","Be aware of the keys vs key_list code inconsistency if --attributes or --both fails unexpectedly."],"tags":["drgn","input-validation","command-args","latent-bug"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}