{"record":{"id":"d3a49a1b5e177d80","repo":"google/python-fire","slug":"missing-required-flags","errorCode":null,"errorMessage":"Missing required flags:","messagePattern":"Missing required flags:","errorType":"exception","errorClass":"FireError","httpStatus":null,"severity":"error","filePath":"fire/core.py","lineNumber":743,"sourceCode":"    \"\"\"Parses the list of `args` into (varargs, kwargs), remaining_args.\"\"\"\n    kwargs, remaining_kwargs, remaining_args = _ParseKeywordArgs(args, fn_spec)\n\n    # Note: _ParseArgs modifies kwargs.\n    parsed_args, kwargs, remaining_args, capacity = _ParseArgs(\n        fn_spec.args, fn_spec.defaults, num_required_args, kwargs,\n        remaining_args, metadata)\n\n    if fn_spec.varargs or fn_spec.varkw:\n      # If we're allowed *varargs or **kwargs, there's always capacity.\n      capacity = True\n\n    extra_kw = set(kwargs) - set(fn_spec.kwonlyargs)\n    if fn_spec.varkw is None and extra_kw:\n      raise FireError('Unexpected kwargs present:', extra_kw)\n\n    missing_kwonly = set(required_kwonly) - set(kwargs)\n    if missing_kwonly:\n      raise FireError('Missing required flags:', missing_kwonly)\n\n    # If we accept *varargs, then use all remaining arguments for *varargs.\n    if fn_spec.varargs is not None:\n      varargs, remaining_args = remaining_args, []\n    else:\n      varargs = []\n\n    for index, value in enumerate(varargs):\n      varargs[index] = _ParseValue(value, None, None, metadata)\n\n    varargs = parsed_args + varargs\n    remaining_args += remaining_kwargs\n\n    consumed_args = args[:len(args) - len(remaining_args)]\n    return (varargs, kwargs), consumed_args, remaining_args, capacity\n\n  return _ParseFn\n","sourceCodeStart":725,"sourceCodeEnd":761,"githubUrl":"https://github.com/google/python-fire/blob/716bbc23d7eca949fdb682172283c8d18f742cb6/fire/core.py#L725-L761","documentation":"Python keyword-only parameters without defaults (required_kwonly) must be supplied by the caller. Fire raises FireError('Missing required flags:', missing_kwonly) naming the flags that were not provided when calling the function through the CLI.","triggerScenarios":"Calling fn(*, required_a, required_b=2) without passing --required_a; programmatic Fire usage constructing kwargs that omit a required keyword-only arg.","commonSituations":"Functions converted to keyword-only args (after the * in signature) that scripts still call positionally; CI invocations missing flags that a developer passes interactively.","solutions":["Supply the missing flag: mytool run --required_a=value","Give the parameter a default value in the signature","Wrap with a check in the component to produce a friendlier message"],"exampleFix":"// before\ndef deploy(*, env): ...  # invoked: deploy\n// after\n$ deploy --env=prod   # or: def deploy(*, env='dev'): ...","handlingStrategy":"validation","validationCode":"spec = inspect.signature(fn)\nmissing = [n for n, p in spec.parameters.items()\n           if p.kind == p.KEYWORD_ONLY and p.default is p.empty and n not in supplied]\nif missing:\n    raise TypeError(f'missing required flags: {missing}')","typeGuard":null,"tryCatchPattern":"try:\n    fire.Fire(component)\nexcept fire.core.FireError as e:\n    if 'Missing required flags' in str(e):\n        print('supply required flags; see -- --help', file=sys.stderr)\n        sys.exit(2)\n    raise","preventionTips":["Provide defaults for keyword-only params when feasible","Validate required flags in wrapper scripts before invoking the CLI","Document required flags and test invocations in CI"],"tags":["python","cli","keyword-only","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"716bbc23d7eca949fdb682172283c8d18f742cb6","analyzedAt":"2026-08-28T21:57:47.200Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}