use thiserror::Error;
use http::header::ToStrError;
use rswappalyzer_engine::CoreError;
use serde_json::Error as SerdeJsonError;
use std::{
io::{Error as IoError, ErrorKind},
time::SystemTimeError,
};
use url::ParseError as UrlParseError;
#[derive(Error, Debug)]
pub enum RswError {
#[error("Core error: {0}")]
CoreError(#[from] CoreError),
#[error("IO operation failed: {0}")]
IoError(#[from] IoError),
#[error("URL parse failed: {0}")]
UrlError(#[from] UrlParseError),
#[error("Invalid input: {0}")]
InvalidInput(String),
#[error("Header field to string conversion failed: {0}")]
HeaderToStrError(#[from] ToStrError),
#[error("System time calculation failed: {0}")]
SystemTimeError(#[from] SystemTimeError),
#[error("Rule config error: {0}")]
RuleConfigError(String),
#[error("Rule load failed: {0}")]
RuleLoadError(String),
#[error("Rule conversion failed: {0}")]
RuleConvertError(String),
#[error("Rule cache operation failed: {0}")]
RuleCacheError(String),
#[error("Rule parse failed: {0}")]
RuleParseError(String),
#[error("Detector not initialized: {0}")]
DetectorNotInitialized(String),
#[error("Detector initialization failed: {0}")]
DetectorInitError(String),
#[error("Detection failed: {0}")]
DetectError(String),
#[error("Network operation failed: {0}")]
NetworkError(String),
#[error("JSON parse/serialize failed: {0}")]
JsonError(#[from] SerdeJsonError),
#[error("Async task execution failed: {0}")]
AsyncTaskError(String),
#[error("Feature disabled: {0}")]
FeatureDisabled(String)
}
impl RswError {
pub fn is_not_found(&self) -> bool {
matches!(
self,
RswError::IoError(e) if e.kind() == ErrorKind::NotFound
)
}
}
pub type RswResult<T> = Result<T, RswError>;