Skip to content

fix(cli): throw FatalConfigError instead of process.exit in parseArguments#27987

Closed
rmedranollamas wants to merge 5 commits into
google-gemini:mainfrom
rmedranollamas:fix/arg-parse-exit-27974
Closed

fix(cli): throw FatalConfigError instead of process.exit in parseArguments#27987
rmedranollamas wants to merge 5 commits into
google-gemini:mainfrom
rmedranollamas:fix/arg-parse-exit-27974

Conversation

@rmedranollamas

@rmedranollamas rmedranollamas commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Refactored argument parsing to throw FatalConfigError instead of process.exit(1). Moved help/version exit logic to main() to ensure robust execution.

This resolves the issue where E2E tests for --help/--version would timeout (exit code 42) due to the child process inheriting VITEST=true but not being allowed to gracefully process.exit(0) after telemetry timers had started. The condition now strictly prevents process.exit(0) ONLY during in-memory unit tests (VITEST=true AND !GEMINI_CLI_INTEGRATION_TEST), allowing actual integration subprocesses to exit cleanly.

@rmedranollamas rmedranollamas requested a review from a team as a code owner June 17, 2026 14:36
@github-actions github-actions Bot added the size/xs An extra small PR label Jun 17, 2026
@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown

📊 PR Size: size/S

  • Lines changed: 47
  • Additions: +25
  • Deletions: -22
  • Files changed: 4

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the argument parsing logic in the CLI to enhance robustness and testability. By transitioning from immediate process termination to throwing a FatalConfigError, the application can now handle configuration errors more gracefully, particularly within integration test environments. This change ensures that cleanup operations are managed centrally, preventing unintended side effects and test failures, ultimately improving the reliability of the CLI and its testing suite.

Highlights

  • Error Handling Refactor: Replaced direct process.exit(1) calls with throw new FatalConfigError within the parseArguments function to allow for more graceful error management.
  • Cleanup Logic Centralization: Eliminated runExitCleanup() calls from parseArguments, as the top-level main() function's error catch block now centrally handles cleanup operations.
  • Improved Integration Test Stability: Prevented destructive side effects during integration testing, resolving issues with timeouts and hangs in Vitest worker threads caused by abrupt process termination.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors argument parsing in packages/cli/src/config/config.ts to throw a FatalConfigError on failure instead of exiting directly. However, it also removes the runExitCleanup() call and its import when handling --help and --version flags. The feedback correctly points out that bypassing this cleanup before calling process.exit(0) will prevent essential cleanup tasks from running, and recommends restoring both the cleanup call and the import.

Comment thread packages/cli/src/config/config.ts
Comment thread packages/cli/src/config/config.ts Outdated
@gemini-cli gemini-cli Bot added priority/p1 Important and should be addressed in the near term. area/non-interactive Issues related to GitHub Actions, SDK, 3P Integrations, Shell Scripting, Command line automation labels Jun 17, 2026
@github-actions github-actions Bot added the size/s A small PR label Jun 17, 2026
@gemini-cli gemini-cli Bot added the status/need-issue Pull requests that need to have an associated issue. label Jun 17, 2026
@rmedranollamas rmedranollamas force-pushed the fix/arg-parse-exit-27974 branch from 5c1bb96 to 1b5c588 Compare June 19, 2026 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/non-interactive Issues related to GitHub Actions, SDK, 3P Integrations, Shell Scripting, Command line automation priority/p1 Important and should be addressed in the near term. size/s A small PR size/xs An extra small PR status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant