mod categorization;
mod error_ext;
mod reqwest_ext;
mod resolve_ext;
mod stats;
mod types;
pub use categorization::{categorize_reqwest_error, get_retry_strategy, update_error_stats};
pub use error_ext::ErrorExt;
pub use reqwest_ext::ReqwestErrorExt;
pub use resolve_ext::{categorize_resolve_error, DnsResolveErrorKind};
pub use stats::ProcessingStats;
pub use types::{
DatabaseError, ErrorType, FingerprintError, InfoType, InitializationError, MigrationError,
RunScanError, StartupError, WarningType,
};
pub fn log_error_chain(e: &anyhow::Error) {
for cause in e.chain() {
log::error!("{cause}");
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_processing_stats_increment() {
let stats = ProcessingStats::new();
stats.increment_error(ErrorType::ProcessUrlTimeout);
assert_eq!(stats.get_error_count(ErrorType::ProcessUrlTimeout), 1);
stats.increment_warning(WarningType::MissingMetaDescription);
assert_eq!(
stats.get_warning_count(WarningType::MissingMetaDescription),
1
);
stats.increment_info(InfoType::HttpRedirect);
assert_eq!(stats.get_info_count(InfoType::HttpRedirect), 1);
}
#[test]
fn test_processing_stats_multiple_increments() {
let stats = ProcessingStats::new();
stats.increment_error(ErrorType::ProcessUrlTimeout);
stats.increment_error(ErrorType::ProcessUrlTimeout);
stats.increment_error(ErrorType::ProcessUrlTimeout);
assert_eq!(stats.get_error_count(ErrorType::ProcessUrlTimeout), 3);
}
#[test]
fn test_processing_stats_totals() {
let stats = ProcessingStats::new();
stats.increment_error(ErrorType::ProcessUrlTimeout);
stats.increment_error(ErrorType::HttpRequestTimeoutError);
stats.increment_warning(WarningType::MissingMetaDescription);
stats.increment_info(InfoType::HttpRedirect);
assert_eq!(stats.total_errors(), 2);
assert_eq!(stats.total_warnings(), 1);
assert_eq!(stats.total_info(), 1);
}
}