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");