{"record":{"id":"9a0a53f4dd91d9b4","repo":"google/python-fire","slug":"could-not-consume-arg","errorCode":null,"errorMessage":"Could not consume arg:","messagePattern":"Could not consume arg:","errorType":"exception","errorClass":"FireError","httpStatus":null,"severity":"error","filePath":"fire/core.py","lineNumber":649,"sourceCode":"  Returns:\n    component: The component that was found by consuming an arg.\n    consumed_args: The args that were consumed by getting this member.\n    remaining_args: The remaining args that haven't been consumed yet.\n  Raises:\n    FireError: If we cannot consume an argument to get a member.\n  \"\"\"\n  members = dir(component)\n  arg = args[0]\n  arg_names = [\n      arg,\n      arg.replace('-', '_'),  # treat '-' as '_'.\n  ]\n\n  for arg_name in arg_names:\n    if arg_name in members:\n      return getattr(component, arg_name), [arg], args[1:]\n\n  raise FireError('Could not consume arg:', arg)\n\n\ndef _CallAndUpdateTrace(component, args, component_trace, treatment='class',\n                        target=None):\n  \"\"\"Call the component by consuming args from args, and update the FireTrace.\n\n  The component could be a class, a routine, or a callable object. This function\n  calls the component and adds the appropriate action to component_trace.\n\n  Args:\n    component: The component to call\n    args: Args for calling the component\n    component_trace: FireTrace object that contains action trace\n    treatment: Type of treatment used. Indicating whether we treat the component\n        as a class, a routine, or a callable.\n    target: Target in FireTrace element, default is None. If the value is None,\n        the component itself will be used as target.\n  Returns:","sourceCodeStart":631,"sourceCodeEnd":667,"githubUrl":"https://github.com/google/python-fire/blob/716bbc23d7eca949fdb682172283c8d18f742cb6/fire/core.py#L631-L667","documentation":"During traversal, Fire consumes args one at a time by matching them against members (attributes/methods) of the current component. If an argument token cannot be consumed — it matches no accessible member, isn't callable consumable, and isn't a flag — FireError('Could not consume arg:', arg) is raised and recorded in the trace.","triggerScenarios":"Typo in a subcommand name (mytool stat vs mytool start); passing a positional arg to an object whose members don't include it; accessing a private/mangled attribute that isn't in members; passing a bare value where a method name is expected.","commonSituations":"Renamed methods after refactoring; case-sensitivity mistakes; trying to access dict-like keys on an object that only supports attribute access.","solutions":["Check spelling/case of the argument against the component's members","Use `mytool -- --help` to list available members","Expose the needed attribute/method as public","Pass the value as a flag (--name value) if it was meant as an argument"],"exampleFix":"// before\n$ mytool statrt  # typo\n// after\n$ mytool start","handlingStrategy":"validation","validationCode":"args = sys.argv[1:]\nmissing = [a for a in args if not a.startswith('-') and not hasattr(component, a)]\n# note: only meaningful for the first traversal token; prefer --help for full check","typeGuard":null,"tryCatchPattern":"try:\n    fire.Fire(component)\nexcept fire.core.FireError as e:\n    if 'Could not consume arg' in str(e):\n        print('Unknown command; see -- --help', file=sys.stderr)\n        sys.exit(2)\n    raise","preventionTips":["Run `tool -- --help` to see available members before invoking","Keep subcommand names public and consistently cased","Add regression tests for each documented subcommand name"],"tags":["python","cli","argument-parsing"],"backgroundTag":"unrecognized-command-argument","analyzedSha":"716bbc23d7eca949fdb682172283c8d18f742cb6","analyzedAt":"2026-08-28T21:57:47.200Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}