From 2a62c6c1ba02eed068ef2402cfa6056ad770fa6f Mon Sep 17 00:00:00 2001 From: Jeremiah Russell Date: Thu, 2 Oct 2025 15:03:13 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(list):=20improve?= =?UTF-8?q?=20error=20handling=20and=20config=20loading?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - replace google_clis_common with crate::utils for config directory handling - use map_err to propagate errors from API calls --- src/list.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/list.rs b/src/list.rs index f2e2937..cb67800 100644 --- a/src/list.rs +++ b/src/list.rs @@ -1,4 +1,3 @@ -use google_clis_common as common; use google_gmail1::{ Gmail, hyper_rustls::{HttpsConnector, HttpsConnectorBuilder}, @@ -23,10 +22,7 @@ impl List { /// Create a new List struct and add the Gmail api connection. pub async fn new(credential: &str) -> Result { let (config_dir, secret) = { - let config_dir = match common::assure_config_dir_exists("~/.cull-gmail") { - Err(e) => return Err(Error::InvalidOptionsError(e, 3)), - Ok(p) => p, - }; + let config_dir = crate::utils::assure_config_dir_exists("~/.cull-gmail")?; let secret: ApplicationSecret = Credential::load_json_file(credential).into(); (config_dir, secret) @@ -66,7 +62,8 @@ impl List { .messages_list("me") .max_results(self.max_results) .doit() - .await?; + .await + .map_err(Box::new)?; // println!("{list:#?}"); if let Some(messages) = list.messages { @@ -81,7 +78,8 @@ impl List { .format("metadata") .add_metadata_headers("subject") .doit() - .await?; + .await + .map_err(Box::new)?; let mut subject = String::new(); if let Some(payload) = m.payload {