use thiserror::Error;
#[derive(Error, Debug)]
pub enum BrowsingError {
#[error("Configuration error: {0}")]
Config(String),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[error("HTTP error: {0}")]
Http(#[from] reqwest::Error),
#[error("URL parse error: {0}")]
Url(#[from] url::ParseError),
#[error("Browser error: {0}")]
Browser(String),
#[error("CDP error: {0}")]
Cdp(String),
#[error("LLM error: {0}")]
Llm(String),
#[error("Agent error: {0}")]
Agent(String),
#[error("DOM error: {0}")]
Dom(String),
#[error("Tool error: {0}")]
Tool(String),
#[error("Validation error: {0}")]
Validation(String),
#[error("Retry limit exceeded after {0} attempts: {1}")]
RetryLimitExceeded(u32, String),
#[error("Connection lost: {0}")]
ConnectionLost(String),
}
pub type Result<T> = std::result::Result<T, BrowsingError>;
#[cfg(test)]
mod tests {
use super::BrowsingError;
#[test]
fn test_browser_error() {
let err = BrowsingError::Browser("Test error".to_string());
assert!(err.to_string().contains("Test error"));
}
#[test]
fn test_dom_error() {
let err = BrowsingError::Dom("DOM error".to_string());
assert!(err.to_string().contains("DOM error"));
}
#[test]
fn test_tool_error() {
let err = BrowsingError::Tool("Tool error".to_string());
assert!(err.to_string().contains("Tool error"));
}
#[test]
fn test_llm_error() {
let err = BrowsingError::Llm("LLM error".to_string());
assert!(err.to_string().contains("LLM error"));
}
#[test]
fn test_config_error() {
let err = BrowsingError::Config("Config error".to_string());
assert!(err.to_string().contains("Config error"));
}
#[test]
fn test_error_display() {
let errors = vec![
BrowsingError::Browser("browser".to_string()),
BrowsingError::Dom("dom".to_string()),
BrowsingError::Tool("tool".to_string()),
BrowsingError::Llm("llm".to_string()),
BrowsingError::Config("config".to_string()),
];
for err in errors {
let display = format!("{err}");
assert!(!display.is_empty());
}
}
}