Standardize exit codes#7055
Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @scidomino, 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 significantly refactors the error handling and process exit strategy across the codebase. The primary goal is to standardize how the application terminates due to fatal errors by introducing a hierarchy of FatalError classes, each with a specific exit code. This change centralizes the process.exit() calls to a single point, making error handling more predictable and easier to manage. Instead of scattered console.error and process.exit(1) statements, the application now throws specific error types, which are then caught and used to determine the appropriate exit status.
Highlights
- Standardized Fatal Error Handling: A new
FatalErrorclass and its specialized subclasses (e.g.,FatalAuthenticationError,FatalConfigError,FatalSandboxError) have been introduced in@google/gemini-cli-core. These classes encapsulate error messages and specific exit codes, providing a standardized way to signal different types of fatal application errors. - Refactored Error Propagation: Across the
packages/cliandpackages/coremodules, numerous instances of directconsole.errorfollowed byprocess.exit(1)have been replaced. Instead, the code now throws instances of the appropriateFatalErrorsubclass, allowing for more structured error propagation and centralized exit management. - Centralized Process Exit Logic: The main entry point (
packages/cli/index.ts) has been updated to catch any uncaughtFatalErrorinstances. When aFatalErroris caught, its associatedexitCodeis used to terminate the process, ensuring that the application exits with a meaningful status code corresponding to the error type. - Updated Testing Methodology: Test files, particularly in
packages/cli/src/gemini.test.tsxandpackages/cli/src/nonInteractiveCli.test.ts, have been modified to assert that specificFatalErrorsubclasses are thrown under error conditions, rather than mocking and checkingprocess.exit()calls. This aligns tests with the new error handling paradigm.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| 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 issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize 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 counter productive. 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.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
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. ↩
There was a problem hiding this comment.
Code Review
This pull request effectively standardizes exit codes by introducing a FatalError class hierarchy and replacing direct process.exit() calls with error throwing. This improves error handling and makes the exit codes more meaningful. The changes are well-implemented across the codebase, including updates to tests to reflect the new behavior. I've found one critical issue in the construction of an error message which would lead to incorrect information being displayed to the user. My review includes a suggestion to fix this.
818c48d to
4aeaa5e
Compare
Code Coverage Summary
CLI Package - Full Text ReportCore Package - Full Text ReportFor detailed HTML reports, please see the 'coverage-reports-22.x-ubuntu-latest' artifact from the main CI run. |
4aeaa5e to
097a865
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request effectively standardizes exit codes by introducing a FatalError class hierarchy and centralizing the exit logic. The changes are consistently applied across the codebase, and the new exit codes are well-documented. I've found one issue related to double-logging of fatal errors in non-interactive mode, which should be addressed to avoid confusing output for users.
This double logging is intentional. |
| | 2 | `FatalInputError` | Invalid or missing input was provided to the CLI. (non-interactive mode only) | | ||
| | 3 | `FatalConfigError` | A configuration file (`settings.json`) is invalid or contains errors. | | ||
| | 4 | `FatalSandboxError` | An error occurred with the sandboxing environment (e.g., Docker, Podman, or Seatbelt). | | ||
| | 5 | `FatalTurnLimitedError` | The maximum number of conversational turns for the session was reached. (non-interactive mode only) | |
There was a problem hiding this comment.
this would be useful here: google-github-actions/run-gemini-cli#205
097a865 to
ed011ee
Compare
TLDR
Introduce FatalError to centralize process.exit() calling.
Reviewer Test Plan
Testing Matrix
Linked issues / bugs
Fixes #6745