♻️ refactor(list): improve error handling and config loading

- replace google_clis_common with crate::utils for config directory handling
- use map_err to propagate errors from API calls
This commit is contained in:
Jeremiah Russell
2025-10-02 15:03:13 +01:00
committed by Jeremiah Russell
parent 475917b27d
commit 2a62c6c1ba

View File

@@ -1,4 +1,3 @@
use google_clis_common as common;
use google_gmail1::{ use google_gmail1::{
Gmail, Gmail,
hyper_rustls::{HttpsConnector, HttpsConnectorBuilder}, hyper_rustls::{HttpsConnector, HttpsConnectorBuilder},
@@ -23,10 +22,7 @@ impl List {
/// Create a new List struct and add the Gmail api connection. /// Create a new List struct and add the Gmail api connection.
pub async fn new(credential: &str) -> Result<Self, Error> { pub async fn new(credential: &str) -> Result<Self, Error> {
let (config_dir, secret) = { let (config_dir, secret) = {
let config_dir = match common::assure_config_dir_exists("~/.cull-gmail") { let config_dir = crate::utils::assure_config_dir_exists("~/.cull-gmail")?;
Err(e) => return Err(Error::InvalidOptionsError(e, 3)),
Ok(p) => p,
};
let secret: ApplicationSecret = Credential::load_json_file(credential).into(); let secret: ApplicationSecret = Credential::load_json_file(credential).into();
(config_dir, secret) (config_dir, secret)
@@ -66,7 +62,8 @@ impl List {
.messages_list("me") .messages_list("me")
.max_results(self.max_results) .max_results(self.max_results)
.doit() .doit()
.await?; .await
.map_err(Box::new)?;
// println!("{list:#?}"); // println!("{list:#?}");
if let Some(messages) = list.messages { if let Some(messages) = list.messages {
@@ -81,7 +78,8 @@ impl List {
.format("metadata") .format("metadata")
.add_metadata_headers("subject") .add_metadata_headers("subject")
.doit() .doit()
.await?; .await
.map_err(Box::new)?;
let mut subject = String::new(); let mut subject = String::new();
if let Some(payload) = m.payload { if let Some(payload) = m.payload {