Files
rustytorch/crates/tooling/rtx-eval/src/error.rs
T
builderandClaude Sonnet 4.6 301f223b91 refactor(rustytorch): full clean review 2026-04-30
- fix(workspace): exclude crates/training/rtx-distributed from workspace members
  — RNCCL path deps absent in standalone checkout blocked all cargo operations
- refactor(rtx-backend-webgpu): split compute.rs (1654 lines) into compute/mod.rs
  (1040) + compute/conv.rs (628) — both within 1250-line limit
- fix(rtx-bench): add missing src/bin/main.rs declared in [[bin]] Cargo.toml entry
- fix(gitignore): narrow `bin/` exclusion to /bin/ only; add !**/src/bin/ exception
  to allow Rust source binary directories
- style(rtx-eval): 67x "literal".to_string() → "literal".to_owned() in automation,
  validation, metrics, lib, core, error modules and build.rs

All tests pass (64 tests across rtx-eval + rtx-backend-webgpu, 0 failures).
Clippy clean (-D warnings) on all changed crates.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-04-30 08:27:50 -07:00

193 lines
4.9 KiB
Rust

//! Error types for RTX-Eval benchmarking framework
use thiserror::Error;
/// RTX-Eval error types
#[derive(Error, Debug)]
pub enum RTXEvalError {
#[error("Benchmark execution failed: {message}")]
BenchmarkFailed { message: String },
#[error("Dataset loading error: {dataset} - {source}")]
DatasetError {
dataset: String,
#[source]
source: Box<dyn std::error::Error + Send + Sync>,
},
#[error("Model inference failed: {model} - {message}")]
InferenceError { model: String, message: String },
#[error("Metrics calculation error: {metric} - {message}")]
MetricsError { metric: String, message: String },
#[error("Configuration error: {message}")]
ConfigError { message: String },
#[error("GPU acceleration error: {message}")]
GpuError { message: String },
#[error("Distributed evaluation error: {message}")]
DistributedError { message: String },
#[error("Timeout error: benchmark {benchmark} exceeded {timeout_secs}s")]
TimeoutError {
benchmark: String,
timeout_secs: u64,
},
#[error("Validation error: {message}")]
ValidationError { message: String },
#[error("IO error: {message}")]
IoError {
message: String,
#[source]
source: std::io::Error,
},
#[error("Serialization error: {message}")]
SerializationError {
message: String,
#[source]
source: serde_json::Error,
},
#[error("Network error: {message}")]
NetworkError {
message: String,
#[source]
source: reqwest::Error,
},
#[error("Competitor comparison failed: {message}")]
CompetitorError { message: String },
#[error("Resource allocation error: {resource} - {message}")]
ResourceError { resource: String, message: String },
#[error("Benchmark suite initialization failed: {message}")]
InitializationError { message: String },
}
impl From<std::io::Error> for RTXEvalError {
fn from(err: std::io::Error) -> Self {
Self::IoError {
message: err.to_string(),
source: err,
}
}
}
impl From<serde_json::Error> for RTXEvalError {
fn from(err: serde_json::Error) -> Self {
Self::SerializationError {
message: err.to_string(),
source: err,
}
}
}
impl From<reqwest::Error> for RTXEvalError {
fn from(err: reqwest::Error) -> Self {
Self::NetworkError {
message: err.to_string(),
source: err,
}
}
}
impl From<anyhow::Error> for RTXEvalError {
fn from(err: anyhow::Error) -> Self {
Self::ValidationError {
message: err.to_string(),
}
}
}
/// Result type for RTX-Eval operations
pub type RTXEvalResult<T> = Result<T, RTXEvalError>;
/// Macro for creating benchmark failed errors
#[macro_export]
macro_rules! benchmark_error {
($msg:expr) => {
$crate::error::RTXEvalError::BenchmarkFailed {
message: $msg.to_string(),
}
};
($fmt:expr, $($arg:tt)*) => {
$crate::error::RTXEvalError::BenchmarkFailed {
message: format!($fmt, $($arg)*),
}
};
}
/// Macro for creating metrics errors
#[macro_export]
macro_rules! metrics_error {
($metric:expr, $msg:expr) => {
$crate::error::RTXEvalError::MetricsError {
metric: $metric.to_string(),
message: $msg.to_string(),
}
};
($metric:expr, $fmt:expr, $($arg:tt)*) => {
$crate::error::RTXEvalError::MetricsError {
metric: $metric.to_string(),
message: format!($fmt, $($arg)*),
}
};
}
/// Macro for creating validation errors
#[macro_export]
macro_rules! validation_error {
($msg:expr) => {
$crate::error::RTXEvalError::ValidationError {
message: $msg.to_string(),
}
};
($fmt:expr, $($arg:tt)*) => {
$crate::error::RTXEvalError::ValidationError {
message: format!($fmt, $($arg)*),
}
};
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_error_creation() {
let err = RTXEvalError::BenchmarkFailed {
message: "Test error".to_owned(),
};
assert_eq!(err.to_string(), "Benchmark execution failed: Test error");
}
#[test]
fn test_benchmark_error_macro() {
let err = benchmark_error!("Test benchmark error");
match err {
RTXEvalError::BenchmarkFailed { message } => {
assert_eq!(message, "Test benchmark error");
}
_ => panic!("Wrong error type"),
}
}
#[test]
fn test_metrics_error_macro() {
let err = metrics_error!("BLEU", "Score calculation failed");
match err {
RTXEvalError::MetricsError { metric, message } => {
assert_eq!(metric, "BLEU");
assert_eq!(message, "Score calculation failed");
}
_ => panic!("Wrong error type"),
}
}
}