Fix clippy warnings: replace unwrap/expect calls with proper error handling
- Replace unwrap() in detection.rs runtime creation with error handling - Fix expect() in Default impl with proper panic message - Replace unwrap() in streaming.rs mutex locks with error handling - Replace unwrap() in ebpf.rs ring buffer locks with error handling - Fix unwrap() in hooks.rs CString creation with error handling - Remove needless borrows in yara_engine.rs iterators - Apply cargo fmt formatting across all files All changes maintain functional behavior while improving error handling robustness.
This commit is contained in:
@@ -265,9 +265,14 @@ impl DetectionEngine {
|
||||
let yara_result = match tokio::runtime::Handle::try_current() {
|
||||
Ok(handle) => handle
|
||||
.block_on(async { yara_engine.scan_process(process, memory_regions).await }),
|
||||
Err(_) => tokio::runtime::Runtime::new()
|
||||
.unwrap()
|
||||
.block_on(async { yara_engine.scan_process(process, memory_regions).await }),
|
||||
Err(_) => {
|
||||
let runtime =
|
||||
tokio::runtime::Runtime::new().map_err(|e| GhostError::Configuration {
|
||||
message: format!("Failed to create async runtime: {}", e),
|
||||
})?;
|
||||
runtime
|
||||
.block_on(async { yara_engine.scan_process(process, memory_regions).await })
|
||||
}
|
||||
};
|
||||
|
||||
if let Ok(yara_result) = yara_result {
|
||||
@@ -676,6 +681,10 @@ impl DetectionEngine {
|
||||
|
||||
impl Default for DetectionEngine {
|
||||
fn default() -> Self {
|
||||
Self::new().expect("Failed to create default DetectionEngine")
|
||||
// For Default trait, we need to provide a working instance.
|
||||
// If this fails, we'll have to panic as Default cannot return Error.
|
||||
Self::new().unwrap_or_else(|e| {
|
||||
panic!("Failed to create default DetectionEngine: {}", e);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user