Removed a lot of unwraps
Build Library / Build Library (push) Successful in 5m2s

Removing the unwraps now has better error handling and will cause the program to crash with crash dumps instead of panic!
This commit is contained in:
brotoskyj
2025-11-21 12:20:11 -05:00
parent 697d923172
commit 303ecd8368
5 changed files with 37 additions and 11 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ dependencies = [
[[package]] [[package]]
name = "airlock_libs" name = "airlock_libs"
version = "3.1.2" version = "3.2.0"
dependencies = [ dependencies = [
"chrono", "chrono",
"indicatif", "indicatif",
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "airlock_libs" name = "airlock_libs"
version = "3.1.2" version = "3.2.0"
edition = "2024" edition = "2024"
[lib] [lib]
+1 -1
View File
@@ -4,7 +4,7 @@ build-backend = "maturin"
[project] [project]
name = "airlock_libs" name = "airlock_libs"
version = "3.1.2" version = "3.2.0"
description = "Airlock Digital API Wrapper" description = "Airlock Digital API Wrapper"
readme = "README.md" readme = "README.md"
license = { text = "AGPL-3.0-only" } license = { text = "AGPL-3.0-only" }
+33 -7
View File
@@ -25,6 +25,7 @@ use std::{
str::FromStr, str::FromStr,
}; };
#[allow(non_snake_case)]
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]
struct TelemetryConfig { struct TelemetryConfig {
TELEMETRY: bool, TELEMETRY: bool,
@@ -86,13 +87,25 @@ pub fn pull_policy_exec_histories(
) )
.into(); .into();
let writeable_filepath = file_path.clone(); let writeable_filepath = file_path.clone();
if !file_path.exists() { if !&file_path.exists() {
if let Some(parent_dir) = file_path.parent() if let Some(parent_dir) = &file_path.parent()
&& !parent_dir.exists() && !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 { let data = ApiResponse {
error: "Success".to_string(), error: "Success".to_string(),
@@ -135,18 +148,31 @@ pub fn pull_policy_exec_histories(
); );
cx.span() cx.span()
.set_status(Status::error("Client Failed to Build")); .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<PyAny> = py_self; let api: Py<PyAny> = py_self;
let cutoff = Local::now().naive_local() - Duration::days(days); 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| { tracer.in_span("Airlock Data Retreival", |cx| {
let span = cx.span(); let span = cx.span();
span.set_attribute(Key::new("Days").string(days.to_string().to_string())); span.set_attribute(Key::new("Days").string(days.to_string().to_string()));
loop { 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 execution_histories = tracer.in_span(checkpoint_number.to_string(), |cx| {
let results: ApiResponse = history_logging( let results: ApiResponse = history_logging(
py, py,
+1 -1
View File
@@ -11,4 +11,4 @@ urllib3==2.5.0
pyperclip==1.11.0 pyperclip==1.11.0
--extra-index-url https://git.racooncity.org/api/packages/brotoskyj/pypi/simple/ --extra-index-url https://git.racooncity.org/api/packages/brotoskyj/pypi/simple/
airlock_libs==3.1.2 airlock_libs==3.2.0