mirror of
https://github.com/ApfelTeeSaft/ia-get.git
synced 2026-08-26 19:23:36 +00:00
refactor(main): centralise exit logic by returning Result
Removes direct calls to `std::process::exit` from `fetch_xml_metadata` and error handling blocks within `main`. These functions now propagate errors by returning `Result`. This change improves testability and aligns with idiomatic Rust error handling, allowing `main` to be the single point of exit for the application on error. Spinner messages for context are retained.
This commit is contained in:
committed by
Martin Wimpress
parent
8c739b0da3
commit
a7af6f5c85
+2
-5
@@ -13,7 +13,6 @@ use ia_get::archive_metadata::{XmlFiles, parse_xml_files};
|
||||
use indicatif::ProgressStyle;
|
||||
use reqwest::Client;
|
||||
use clap::Parser;
|
||||
use std::process;
|
||||
|
||||
/// Checks if a URL is accessible by sending a HEAD request
|
||||
async fn is_url_accessible(url: &str, client: &Client) -> Result<()> {
|
||||
@@ -74,8 +73,7 @@ async fn fetch_xml_metadata(
|
||||
// Check XML URL accessibility
|
||||
if let Err(e) = is_url_accessible(&xml_url, client).await {
|
||||
spinner.finish_with_message(format!("🔴 XML metadata not accessible: {}", xml_url));
|
||||
eprintln!("╰╼ Exiting due to error: {}", e);
|
||||
process::exit(1);
|
||||
return Err(e); // Propagate the error
|
||||
}
|
||||
|
||||
spinner.set_message("Parsing archive metadata... 👀");
|
||||
@@ -130,8 +128,7 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
||||
// Check URL accessibility
|
||||
if let Err(e) = is_url_accessible(&cli.url, &client).await {
|
||||
spinner.finish_with_message(format!("🔴 Archive.org URL not accessible: {}", cli.url));
|
||||
eprintln!("╰╼ Exiting due to error: {}", e);
|
||||
process::exit(1);
|
||||
return Err(e.into()); // Propagate error
|
||||
}
|
||||
|
||||
// Fetch and parse XML metadata in one operation
|
||||
|
||||
Reference in New Issue
Block a user