diff --git a/.changeset/fix-auth-error-consistency.md b/.changeset/fix-auth-error-consistency.md new file mode 100644 index 00000000..1c319823 --- /dev/null +++ b/.changeset/fix-auth-error-consistency.md @@ -0,0 +1,5 @@ +--- +"@googleworkspace/cli": patch +--- + +fix: report auth errors instead of silently proceeding unauthenticated diff --git a/src/helpers/calendar.rs b/src/helpers/calendar.rs index 8b07fbd5..5edf803f 100644 --- a/src/helpers/calendar.rs +++ b/src/helpers/calendar.rs @@ -151,7 +151,12 @@ TIPS: let scopes_str: Vec<&str> = scopes.iter().map(|s| s.as_str()).collect(); 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}"))) + } }; let events_res = doc.resources.get("events").ok_or_else(|| { diff --git a/src/helpers/chat.rs b/src/helpers/chat.rs index 92d8e79b..21f76a96 100644 --- a/src/helpers/chat.rs +++ b/src/helpers/chat.rs @@ -80,7 +80,12 @@ TIPS: let scope_strs: Vec<&str> = scopes.iter().map(|s| s.as_str()).collect(); let (token, auth_method) = match auth::get_token(&scope_strs).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!("Chat auth failed: {e}"))) + } }; // Method: spaces.messages.create diff --git a/src/helpers/docs.rs b/src/helpers/docs.rs index e847dfbf..6b1ace28 100644 --- a/src/helpers/docs.rs +++ b/src/helpers/docs.rs @@ -72,7 +72,12 @@ TIPS: let scope_strs: Vec<&str> = scopes.iter().map(|s| s.as_str()).collect(); let (token, auth_method) = match auth::get_token(&scope_strs).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!("Docs auth failed: {e}"))) + } }; // Method: documents.batchUpdate diff --git a/src/helpers/drive.rs b/src/helpers/drive.rs index f23aa555..8799321e 100644 --- a/src/helpers/drive.rs +++ b/src/helpers/drive.rs @@ -98,7 +98,12 @@ TIPS: let scopes: Vec<&str> = create_method.scopes.iter().map(|s| s.as_str()).collect(); let (token, auth_method) = match auth::get_token(&scopes).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!("Drive auth failed: {e}"))) + } }; executor::execute_method( diff --git a/src/helpers/script.rs b/src/helpers/script.rs index 8685afb2..0443a087 100644 --- a/src/helpers/script.rs +++ b/src/helpers/script.rs @@ -105,7 +105,12 @@ TIPS: let scopes: Vec<&str> = update_method.scopes.iter().map(|s| s.as_str()).collect(); let (token, auth_method) = match auth::get_token(&scopes).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!("Script auth failed: {e}"))) + } }; let params = json!({ diff --git a/src/helpers/sheets.rs b/src/helpers/sheets.rs index 9e347b4d..7ae030d6 100644 --- a/src/helpers/sheets.rs +++ b/src/helpers/sheets.rs @@ -108,7 +108,12 @@ TIPS: let scope_strs: Vec<&str> = scopes.iter().map(|s| s.as_str()).collect(); let (token, auth_method) = match auth::get_token(&scope_strs).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!("Sheets auth failed: {e}"))) + } }; let spreadsheets_res = doc.resources.get("spreadsheets").ok_or_else(|| { @@ -166,7 +171,12 @@ TIPS: let scope_strs: Vec<&str> = scopes.iter().map(|s| s.as_str()).collect(); let (token, auth_method) = match auth::get_token(&scope_strs).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!("Sheets auth failed: {e}"))) + } }; executor::execute_method(