Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/fix-auth-error-logging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@anthropic/gws": patch
---

Log auth errors to stderr instead of silently swallowing them

Previously, when OAuth authentication failed in the main CLI flow, the error
was silently discarded and the request proceeded unauthenticated. This caused
confusing 401/403 responses from the API with no indication of the root cause.

Now prints the original auth error and a hint to stderr, making it clear why
authentication failed (expired token, missing credentials, wrong account, etc.).
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,11 @@ async fn run() -> Result<(), GwsError> {
// Authenticate: try OAuth, otherwise proceed unauthenticated
let (token, auth_method) = match auth::get_token(&scopes, account.as_deref()).await {
Ok(t) => (Some(t), executor::AuthMethod::OAuth),
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 or GOOGLE_WORKSPACE_CLI_CREDENTIALS_FILE");
(None, executor::AuthMethod::None)
}
Comment on lines +241 to +245
Copy link
Contributor

Choose a reason for hiding this comment

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

high

While logging the error is a great improvement, the program currently proceeds to make an API request without authentication, which is guaranteed to fail. This results in a second error message for the user.

It would be better to fail fast here by returning an error immediately after logging the authentication failure. This avoids the unnecessary network request and provides a cleaner, single error message to the user.

        Err(e) => {
            eprintln!("warning: authentication failed: {e:#}");
            eprintln!("hint: run `gws auth login` to authenticate, or set GOOGLE_WORKSPACE_CLI_TOKEN or GOOGLE_WORKSPACE_CLI_CREDENTIALS_FILE");
            return Err(GwsError::Auth(
                "Authentication failed. See stderr for details.".to_string(),
            ));
        }

};

// Execute
Expand Down