fix: replace unwrap() on required arguments in calendar helper

Replaced `.unwrap()` calls for `calendar`, `summary`, `start`, and `end`
arguments with proper error handling using `.ok_or_else()`. This
prevents potential panics if the `clap` configuration were to change and
instead returns a structured `GwsError::Validation` error.

Added a changeset file for `@googleworkspace/cli` as a patch-level
update.

Co-authored-by: jpoehnelt <3392975+jpoehnelt@users.noreply.github.com>
This commit is contained in:
google-labs-jules[bot]
2026-03-18 15:53:32 +00:00
parent 6f92e5b5f6
commit bbaaecdc88
2 changed files with 17 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@googleworkspace/cli": patch
---
Remove unwrap() on required arguments in the calendar helper to improve error handling and prevent potential panics.
+12 -4
View File
@@ -424,10 +424,18 @@ fn build_insert_request(
matches: &ArgMatches,
doc: &crate::discovery::RestDescription,
) -> Result<(String, String, Vec<String>), GwsError> {
let calendar_id = matches.get_one::<String>("calendar").unwrap();
let summary = matches.get_one::<String>("summary").unwrap();
let start = matches.get_one::<String>("start").unwrap();
let end = matches.get_one::<String>("end").unwrap();
let calendar_id = matches
.get_one::<String>("calendar")
.ok_or_else(|| GwsError::Validation("Missing required argument: calendar".to_string()))?;
let summary = matches
.get_one::<String>("summary")
.ok_or_else(|| GwsError::Validation("Missing required argument: summary".to_string()))?;
let start = matches
.get_one::<String>("start")
.ok_or_else(|| GwsError::Validation("Missing required argument: start".to_string()))?;
let end = matches
.get_one::<String>("end")
.ok_or_else(|| GwsError::Validation("Missing required argument: end".to_string()))?;
let location = matches.get_one::<String>("location");
let description = matches.get_one::<String>("description");
let attendees_vals = matches.get_many::<String>("attendee");