From 303ecd83686bdedb4b28e3bcaabd85c9933d9519 Mon Sep 17 00:00:00 2001 From: brotoskyj Date: Fri, 21 Nov 2025 12:20:11 -0500 Subject: [PATCH] Removed a lot of unwraps Removing the unwraps now has better error handling and will cause the program to crash with crash dumps instead of panic! --- airlock_libs/Cargo.lock | 2 +- airlock_libs/Cargo.toml | 2 +- airlock_libs/pyproject.toml | 2 +- airlock_libs/src/services.rs | 40 +++++++++++++++++++++++++++++------- requirements.txt | 2 +- 5 files changed, 37 insertions(+), 11 deletions(-) diff --git a/airlock_libs/Cargo.lock b/airlock_libs/Cargo.lock index fb2d657..7d41bb2 100644 --- a/airlock_libs/Cargo.lock +++ b/airlock_libs/Cargo.lock @@ -26,7 +26,7 @@ dependencies = [ [[package]] name = "airlock_libs" -version = "3.1.2" +version = "3.2.0" dependencies = [ "chrono", "indicatif", diff --git a/airlock_libs/Cargo.toml b/airlock_libs/Cargo.toml index 1fb0612..7ae3aaa 100644 --- a/airlock_libs/Cargo.toml +++ b/airlock_libs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "airlock_libs" -version = "3.1.2" +version = "3.2.0" edition = "2024" [lib] diff --git a/airlock_libs/pyproject.toml b/airlock_libs/pyproject.toml index b646277..32a8a0d 100644 --- a/airlock_libs/pyproject.toml +++ b/airlock_libs/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "maturin" [project] name = "airlock_libs" -version = "3.1.2" +version = "3.2.0" description = "Airlock Digital API Wrapper" readme = "README.md" license = { text = "AGPL-3.0-only" } diff --git a/airlock_libs/src/services.rs b/airlock_libs/src/services.rs index c38adeb..7d1c1a5 100644 --- a/airlock_libs/src/services.rs +++ b/airlock_libs/src/services.rs @@ -25,6 +25,7 @@ use std::{ str::FromStr, }; +#[allow(non_snake_case)] #[derive(Deserialize, Debug)] struct TelemetryConfig { TELEMETRY: bool, @@ -86,13 +87,25 @@ pub fn pull_policy_exec_histories( ) .into(); let writeable_filepath = file_path.clone(); - if !file_path.exists() { - if let Some(parent_dir) = file_path.parent() + if !&file_path.exists() { + if let Some(parent_dir) = &file_path.parent() && !parent_dir.exists() { - fs::create_dir_all(parent_dir).unwrap(); + match fs::create_dir_all(parent_dir) { + Ok(_) => {}, + Err(e) => { + println!("Failed to Create Directory {:?}: {}", parent_dir, e); + std::process::abort(); + } + } + } + match fs::File::create(&file_path) { + Ok(_) => {}, + Err(e) => { + println!("Failed to Create Directory {:?}: {}", &file_path, e); + std::process::abort(); + } } - fs::File::create(file_path).unwrap(); } let data = ApiResponse { error: "Success".to_string(), @@ -135,18 +148,31 @@ pub fn pull_policy_exec_histories( ); cx.span() .set_status(Status::error("Client Failed to Build")); - panic!("Failed to Build Client: {:?}", client_result); + println!("Failed to Build Client: {:?}", client_result); + std::process::abort(); } } }); let api: Py = py_self; let cutoff = Local::now().naive_local() - Duration::days(days); - let mut f = File::open(&writeable_filepath).unwrap(); + let mut f = match File::open(&writeable_filepath) { + Ok(f) => f, + Err(e) => { + println!("Failed to Access {:?}: {}", &writeable_filepath, e); + std::process::abort(); + } + }; tracer.in_span("Airlock Data Retreival", |cx| { let span = cx.span(); span.set_attribute(Key::new("Days").string(days.to_string().to_string())); loop { - f.seek(SeekFrom::Start(0)).unwrap(); + match f.seek(SeekFrom::Start(0)) { + Ok(_) => {}, + Err(e) => { + println!("Failed to seek start of {:?}: {}", f, e); + std::process::abort(); + } + } let execution_histories = tracer.in_span(checkpoint_number.to_string(), |cx| { let results: ApiResponse = history_logging( py, diff --git a/requirements.txt b/requirements.txt index a89fe9e..7110c1e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,4 +11,4 @@ urllib3==2.5.0 pyperclip==1.11.0 --extra-index-url https://git.racooncity.org/api/packages/brotoskyj/pypi/simple/ -airlock_libs==3.1.2 \ No newline at end of file +airlock_libs==3.2.0 \ No newline at end of file