mirror of
https://github.com/elicpeter/nyx.git
synced 2026-06-27 20:29:39 +02:00
Refactor error handling with NyxResult and enhance debugging
- Replaced `Result` with `NyxResult` across the codebase for consistent error management. - Enhanced `NyxError` with new variants and utility conversions for better flexibility. - Added detailed `tracing::debug` logs in `file.rs` and `walk.rs` for improved traceability. - Simplified conditionals and improved path handling in `file.rs`. - Refined severity filtering logic in `scan.rs`.
This commit is contained in:
parent
0a66a0ae2d
commit
bd788a8373
9 changed files with 81 additions and 43 deletions
|
|
@ -1,6 +1,9 @@
|
|||
use std::fmt;
|
||||
use std::sync::PoisonError;
|
||||
use serde::de::StdError;
|
||||
use thiserror::Error;
|
||||
|
||||
pub type NyxResult<T, E = NyxError> = core::result::Result<T, E>;
|
||||
pub type NyxResult<T, E = NyxError> = Result<T, E>;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum NyxError {
|
||||
|
|
@ -19,6 +22,39 @@ pub enum NyxError {
|
|||
#[error("time error: {0}")]
|
||||
Time(#[from] std::time::SystemTimeError),
|
||||
|
||||
#[error("other: {0}")]
|
||||
Other(String),
|
||||
}
|
||||
#[error("poisoned lock: {0}")]
|
||||
Poison(String),
|
||||
|
||||
#[error(transparent)]
|
||||
Other(#[from] Box<dyn StdError + Send + Sync + 'static>),
|
||||
|
||||
#[error("{0}")]
|
||||
Msg(String),
|
||||
}
|
||||
|
||||
impl<T> From<PoisonError<T>> for NyxError
|
||||
where
|
||||
T: fmt::Debug,
|
||||
{
|
||||
fn from(err: PoisonError<T>) -> Self {
|
||||
NyxError::Poison(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for NyxError {
|
||||
fn from(s: &str) -> Self {
|
||||
NyxError::Msg(s.to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for NyxError {
|
||||
fn from(s: String) -> Self {
|
||||
NyxError::Msg(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Box<dyn std::error::Error>> for NyxError {
|
||||
fn from(err: Box<dyn std::error::Error>) -> Self {
|
||||
NyxError::Msg(err.to_string())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue