Skip to content

fix: log auth errors to stderr instead of silently discarding#190

Open
Bortlesboat wants to merge 1 commit intogoogleworkspace:mainfrom
Bortlesboat:fix/auth-error-logging
Open

fix: log auth errors to stderr instead of silently discarding#190
Bortlesboat wants to merge 1 commit intogoogleworkspace:mainfrom
Bortlesboat:fix/auth-error-logging

Conversation

@Bortlesboat
Copy link
Contributor

Summary

When OAuth authentication fails in the main CLI flow, the error was silently discarded and the request proceeded unauthenticated. Users then received confusing 401/403 API errors with no indication of the root cause (expired token, missing credentials, wrong account, etc.).

Now prints the original error message and a hint to stderr.

Changes

  • src/main.rs: Replace Err(_) => (None, AuthMethod::None) with logging the error and a hint to run gws auth login

Note: The MCP server (mcp_server.rs:430-435) already logs auth failures correctly — this brings the main CLI in line with that pattern.

Test plan

  • CI: cargo test, cargo clippy, cargo fmt
  • Manual: run any API command without auth configured, verify error + hint appear on stderr

@Bortlesboat Bortlesboat requested a review from jpoehnelt as a code owner March 5, 2026 17:31
@changeset-bot
Copy link

changeset-bot bot commented Mar 5, 2026

🦋 Changeset detected

Latest commit: 8408910

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@gemini-code-assist
Copy link
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 significantly enhances the user experience of the CLI by addressing a critical issue where OAuth authentication failures were previously suppressed. By explicitly logging these errors to stderr and providing actionable advice, users will now immediately understand why their commands are failing, thereby reducing frustration and debugging time.

Highlights

  • Improved Authentication Error Handling: Authentication failures in the main CLI flow are now logged to stderr with a helpful hint, preventing silent discarding of errors and confusing API responses.
Changelog
  • .changeset/fix-auth-error-logging.md
    • Added a new changeset file to document the fix for authentication error logging.
  • src/main.rs
    • Modified the main application logic to log authentication errors and provide a hint to stderr.
    • Replaced silent error discarding with explicit error reporting for OAuth authentication failures.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
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 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

  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.

When OAuth authentication fails in the main CLI flow, the error was
silently discarded (`Err(_) => (None, AuthMethod::None)`) and the
request proceeded unauthenticated. Users then received confusing
401/403 API errors with no indication of the actual root cause.

Now prints the original error message and a hint to run
`gws auth login` to stderr, so users immediately understand
why their request failed.
@Bortlesboat Bortlesboat force-pushed the fix/auth-error-logging branch from e9c0694 to 8408910 Compare March 5, 2026 17:34
Copy link
Contributor

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

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 modifies the main CLI flow to log authentication failures to stderr instead of silently discarding them. The change includes printing the error and a hint for the user. My feedback includes a suggestion to make the hint more comprehensive.

Err(_) => (None, executor::AuthMethod::None),
Err(e) => {
eprintln!("warning: authentication failed: {e:#}");
eprintln!("hint: run `gws auth login` to authenticate, or set GOOGLE_WORKSPACE_CLI_TOKEN");
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The hint about authentication methods is helpful, but it's incomplete. It omits the GOOGLE_WORKSPACE_CLI_CREDENTIALS_FILE environment variable, which is another primary way to provide credentials. To provide a more comprehensive hint to the user, it would be better to include it.

Suggested change
eprintln!("hint: run `gws auth login` to authenticate, or set GOOGLE_WORKSPACE_CLI_TOKEN");
eprintln!("hint: run `gws auth login` to authenticate, or set GOOGLE_WORKSPACE_CLI_TOKEN or GOOGLE_WORKSPACE_CLI_CREDENTIALS_FILE");

@jpoehnelt jpoehnelt added area: auth cla: yes This human has signed the Contributor License Agreement. complexity: low Small, straightforward change labels Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: auth cla: yes This human has signed the Contributor License Agreement. complexity: low Small, straightforward change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants