From bbaaecdc88804452108c97d75ba040445c71b142 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 18 Mar 2026 15:53:32 +0000 Subject: [PATCH] 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> --- .changeset/remove-calendar-unwrap.md | 5 +++++ src/helpers/calendar.rs | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 .changeset/remove-calendar-unwrap.md diff --git a/.changeset/remove-calendar-unwrap.md b/.changeset/remove-calendar-unwrap.md new file mode 100644 index 00000000..fc0ead41 --- /dev/null +++ b/.changeset/remove-calendar-unwrap.md @@ -0,0 +1,5 @@ +--- +"@googleworkspace/cli": patch +--- + +Remove unwrap() on required arguments in the calendar helper to improve error handling and prevent potential panics. diff --git a/src/helpers/calendar.rs b/src/helpers/calendar.rs index 5a48233d..72e84299 100644 --- a/src/helpers/calendar.rs +++ b/src/helpers/calendar.rs @@ -424,10 +424,18 @@ fn build_insert_request( matches: &ArgMatches, doc: &crate::discovery::RestDescription, ) -> Result<(String, String, Vec), GwsError> { - let calendar_id = matches.get_one::("calendar").unwrap(); - let summary = matches.get_one::("summary").unwrap(); - let start = matches.get_one::("start").unwrap(); - let end = matches.get_one::("end").unwrap(); + let calendar_id = matches + .get_one::("calendar") + .ok_or_else(|| GwsError::Validation("Missing required argument: calendar".to_string()))?; + let summary = matches + .get_one::("summary") + .ok_or_else(|| GwsError::Validation("Missing required argument: summary".to_string()))?; + let start = matches + .get_one::("start") + .ok_or_else(|| GwsError::Validation("Missing required argument: start".to_string()))?; + let end = matches + .get_one::("end") + .ok_or_else(|| GwsError::Validation("Missing required argument: end".to_string()))?; let location = matches.get_one::("location"); let description = matches.get_one::("description"); let attendees_vals = matches.get_many::("attendee");