{"record":{"id":"7ab5e8597b57f9f7","repo":"google/python-fire","slug":"2","errorCode":"2","errorMessage":"Fire trace and error output displayed on stderr before exiting","messagePattern":"Fire trace and error output displayed on stderr before exiting","errorType":"console","errorClass":"FireExit","httpStatus":null,"severity":"error","filePath":"fire/core.py","lineNumber":139,"sourceCode":"\n  argparser = parser.CreateParser()\n  parsed_flag_args, unused_args = argparser.parse_known_args(flag_args)\n\n  context = {}\n  if parsed_flag_args.interactive or component is None:\n    # Determine the calling context.\n    caller = inspect.stack()[1]\n    caller_frame = caller[0]\n    caller_globals = caller_frame.f_globals\n    caller_locals = caller_frame.f_locals\n    context.update(caller_globals)\n    context.update(caller_locals)\n\n  component_trace = _Fire(component, args, parsed_flag_args, context, name)\n\n  if component_trace.HasError():\n    _DisplayError(component_trace)\n    raise FireExit(2, component_trace)\n  if component_trace.show_trace and component_trace.show_help:\n    output = [f'Fire trace:\\n{component_trace}\\n']\n    result = component_trace.GetResult()\n    help_text = helptext.HelpText(\n        result, trace=component_trace, verbose=component_trace.verbose)\n    output.append(help_text)\n    Display(output, out=sys.stderr)\n    raise FireExit(0, component_trace)\n  if component_trace.show_trace:\n    output = [f'Fire trace:\\n{component_trace}']\n    Display(output, out=sys.stderr)\n    raise FireExit(0, component_trace)\n  if component_trace.show_help:\n    result = component_trace.GetResult()\n    help_text = helptext.HelpText(\n        result, trace=component_trace, verbose=component_trace.verbose)\n    output = [help_text]\n    Display(output, out=sys.stderr)","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/google/python-fire/blob/716bbc23d7eca949fdb682172283c8d18f742cb6/fire/core.py#L121-L157","documentation":"When the component trace produced during command execution contains an error, Fire displays the error and raises FireExit with code 2, printing the Fire trace and help/error output to stderr. This is the standard non-zero exit path for any exception or usage failure that occurs while Fire executes your callable.","triggerScenarios":"Any exception raised inside the target component during fire.Fire() execution (TypeError from wrong args, FireError from consumption failures, user exceptions); also when the traced command fails to resolve and trace/help output is shown.","commonSituations":"CI pipelines where the fired command fails and scripts check exit code 2; typos in member/flag names causing resolution failure; wrong number/type of arguments to the fired function.","solutions":["Read the Fire trace on stderr to find which component/arg failed","Fix the offending argument values, names, or types in the invocation","Wrap risky component logic to convert exceptions into clearer messages","In callers, catch fire.core.FireExit and inspect .code and the trace"],"exampleFix":"// before\nfire.Fire(MyService)  # exits with code 2 on any failure\n// after\ntry:\n    fire.Fire(MyService)\nexcept fire.core.FireExit as e:\n    print(f'fire failed with code {e.code}', file=sys.stderr)\n    sys.exit(e.code)","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try:\n    fire.Fire(component)\nexcept fire.core.FireExit as e:\n    sys.stderr.write(str(e.trace))\n    sys.exit(e.code)  # 2","preventionTips":["Test your CLI commands end-to-end in CI and check exit codes","Read the Fire trace on stderr to pinpoint the failing component","Keep component logic defensive so user errors surface as clear messages"],"tags":["python","cli","exit-code","trace"],"backgroundTag":"cli-exit-code-error","analyzedSha":"716bbc23d7eca949fdb682172283c8d18f742cb6","analyzedAt":"2026-08-28T21:57:47.200Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}