use thiserror::Error;
#[derive(Error, Debug)]
pub enum RurlError {
#[error("HTTP request failed: {0}")]
RequestError(#[from] reqwest::Error),
#[error("Invalid URL: {0}")]
InvalidUrl(String),
#[error("Invalid method: {0}")]
InvalidMethod(String),
#[error("Invalid header format: {0}")]
InvalidHeader(String),
#[error("File read error: {0}")]
FileError(#[from] std::io::Error),
#[error("JSON parse error: {0}")]
JsonError(#[from] serde_json::Error),
#[error("Dataset error: {0}")]
DatasetError(String),
#[error("Performance test error: {0}")]
PerfError(String),
#[error("Data file error: {0}")]
DataFileError(String),
#[error("Substitution error: {0}")]
SubstitutionError(String),
}
pub type Result<T> = std::result::Result<T, RurlError>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_invalid_method_error() {
let error = RurlError::InvalidMethod("INVALID".to_string());
assert!(error.to_string().contains("Invalid method"));
}
#[test]
fn test_invalid_header_error() {
let error = RurlError::InvalidHeader("bad-header".to_string());
assert!(error.to_string().contains("Invalid header format"));
}
#[test]
fn test_dataset_error() {
let error = RurlError::DatasetError("empty file".to_string());
assert!(error.to_string().contains("Dataset error"));
}
#[test]
fn test_data_file_error() {
let error = RurlError::DataFileError("unsupported extension".to_string());
assert!(error.to_string().contains("Data file error"));
assert!(error.to_string().contains("unsupported extension"));
}
}