Skip to content

fix: report auth errors instead of silently proceeding unauthenticated#446

Open
anshul-garg27 wants to merge 1 commit intogoogleworkspace:mainfrom
anshul-garg27:fix/auth-error-consistency
Open

fix: report auth errors instead of silently proceeding unauthenticated#446
anshul-garg27 wants to merge 1 commit intogoogleworkspace:mainfrom
anshul-garg27:fix/auth-error-consistency

Conversation

@anshul-garg27
Copy link
Contributor

Summary

  • Six helper commands silently swallowed authentication failures and proceeded with AuthMethod::None, causing confusing 401 API errors downstream
  • Now they return a clear GwsError::Auth message with the underlying error
  • --dry-run mode still works without auth (consistent with gmail helper pattern)

Affected helpers

Helper File Command
Chat src/helpers/chat.rs +send
Drive src/helpers/drive.rs +upload
Sheets src/helpers/sheets.rs +append, +read
Docs src/helpers/docs.rs +write
Calendar src/helpers/calendar.rs +insert
Script src/helpers/script.rs +push

Root cause

These helpers used a silent fallback pattern:

Err(_) => (None, executor::AuthMethod::None),

The gmail helper already uses the correct pattern:

Err(_) if matches.get_flag("dry-run") => (None, executor::AuthMethod::None),
Err(e) => return Err(GwsError::Auth(format!("... auth failed: {e}"))),

Test plan

  • Verified all 7 call sites across 6 files are updated
  • --dry-run exception preserved for all helpers
  • Existing tests continue to pass

@changeset-bot
Copy link

changeset-bot bot commented Mar 12, 2026

🦋 Changeset detected

Latest commit: 28d7393

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

This PR includes changesets to release 1 package
Name Type
@googleworkspace/cli Patch

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

@googleworkspace-bot googleworkspace-bot added the area: core Core CLI parsing, commands, error handling, utilities label Mar 12, 2026
@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 improves the user experience by enhancing error reporting for authentication failures across several helper commands. Instead of silently proceeding unauthenticated and leading to obscure API errors, these commands now provide clear and actionable GwsError::Auth messages, making it easier for users to diagnose and resolve authentication issues.

Highlights

  • Authentication Error Handling: Six helper commands (Chat, Drive, Sheets, Docs, Calendar, Script) were updated to explicitly report authentication failures with a GwsError::Auth message, preventing silent unauthenticated execution and subsequent confusing 401 API errors.
  • Dry-Run Exception Preserved: The --dry-run flag continues to allow unauthenticated operation for all affected helpers, maintaining consistency with the existing gmail helper pattern.
Changelog
  • .changeset/fix-auth-error-consistency.md
    • Added a new changeset file.
  • src/helpers/calendar.rs
    • Modified authentication error handling to return GwsError::Auth on failure, while preserving --dry-run behavior.
  • src/helpers/chat.rs
    • Modified authentication error handling to return GwsError::Auth on failure, while preserving --dry-run behavior.
  • src/helpers/docs.rs
    • Modified authentication error handling to return GwsError::Auth on failure, while preserving --dry-run behavior.
  • src/helpers/drive.rs
    • Modified authentication error handling to return GwsError::Auth on failure, while preserving --dry-run behavior.
  • src/helpers/script.rs
    • Modified authentication error handling to return GwsError::Auth on failure, while preserving --dry-run behavior.
  • src/helpers/sheets.rs
    • Modified authentication error handling in two locations to return GwsError::Auth on failure, while preserving --dry-run behavior.
Activity
  • No specific review comments or activity have been recorded yet for this pull request.
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 Generative AI Prohibited Use Policy, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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 fixes an issue where authentication failures were silently ignored in several helper commands by making them report auth errors. This change improves user experience by providing clear feedback. The implementation also correctly preserves existing --dry-run functionality. My review includes one suggestion to improve maintainability by refactoring the new, duplicated error handling logic into a shared function.

Six helpers (chat, drive, sheets, docs, calendar, script) silently
swallowed auth failures and proceeded with AuthMethod::None, causing
confusing 401 API errors downstream. Now they return a clear
GwsError::Auth message, with an exception for --dry-run mode where
auth is not needed.

Consistent with the pattern already used in gmail helpers.
@anshul-garg27 anshul-garg27 force-pushed the fix/auth-error-consistency branch from 7dfd190 to 28d7393 Compare March 13, 2026 20:33
@googleworkspace-bot
Copy link
Collaborator

/gemini review

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 correctly fixes a critical issue where authentication failures were being silently ignored across several helper commands. The change to explicitly return an authentication error is a significant improvement for usability and security. I have one suggestion to further improve the maintainability of this new error handling logic by refactoring the duplicated code into a shared helper function.

Comment on lines 152 to 160
let (token, auth_method) = match auth::get_token(&scopes_str).await {
Ok(t) => (Some(t), executor::AuthMethod::OAuth),
Err(_) => (None, executor::AuthMethod::None),
Err(_) if matches.get_flag("dry-run") => {
(None, executor::AuthMethod::None)
}
Err(e) => {
return Err(GwsError::Auth(format!("Calendar auth failed: {e}")))
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This new authentication handling logic is a great improvement. However, this exact match block has been duplicated across multiple helper files (calendar.rs, chat.rs, docs.rs, drive.rs, script.rs, and sheets.rs), and a similar pattern already exists in gmail.rs.

To improve maintainability and avoid potential inconsistencies in the future, consider abstracting this logic into a single, shared helper function. This would centralize the authentication flow, making it easier to update if needed.

For example, you could create a function like this in a shared module (e.g., a new src/helpers/auth_utils.rs or within src/auth.rs):

pub async fn get_auth_token_or_fail(
    scopes: &[&str],
    matches: &clap::ArgMatches,
    service_name: &str,
) -> Result<(Option<String>, crate::executor::AuthMethod), crate::error::GwsError> {
    match crate::auth::get_token(scopes).await {
        Ok(t) => Ok((Some(t), crate::executor::AuthMethod::OAuth)),
        Err(_) if matches.get_flag("dry-run") => Ok((None, crate::executor::AuthMethod::None)),
        Err(e) => Err(crate::error::GwsError::Auth(format!(
            "{} auth failed: {}",
            service_name, e
        ))),
    }
}

Then, each call site could be simplified to a single line:

let (token, auth_method) = crate::helpers::auth_utils::get_auth_token_or_fail(&scopes_str, matches, "Calendar").await?;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Core CLI parsing, commands, error handling, utilities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants