166 lines
4.9 KiB
Rust
166 lines
4.9 KiB
Rust
//! Error types for the autonomous optimization system.
|
|
|
|
use thiserror::Error;
|
|
|
|
/// Errors that can occur during autonomous optimization operations.
|
|
#[derive(Error, Debug)]
|
|
pub enum AutoError {
|
|
/// Runtime error from the underlying compute runtime
|
|
#[error("Runtime error: {0}")]
|
|
Runtime(#[from] rtx_runtime::RuntimeError),
|
|
|
|
/// Tensor operation error
|
|
#[error("Tensor error: {0}")]
|
|
Tensor(#[from] rtx_tensor::TensorError),
|
|
|
|
/// Graph operation error
|
|
#[error("Graph error: {0}")]
|
|
Graph(#[from] rtx_graph::GraphError),
|
|
|
|
/// Evolution framework error
|
|
#[error("Evolution error: {0}")]
|
|
Evolution(#[from] rtx_evolution::EvolutionError),
|
|
|
|
/// Profiler error
|
|
#[error("Profiler error: {0}")]
|
|
Profiler(Box<dyn std::error::Error + Send + Sync>),
|
|
|
|
/// Kernel synthesis error
|
|
#[error("Kernel error: {0}")]
|
|
Kernel(Box<dyn std::error::Error + Send + Sync>),
|
|
|
|
/// Distributed computing error (rtx-distributed temporarily disabled)
|
|
#[error("Distributed error: {0}")]
|
|
Distributed(String),
|
|
|
|
/// Invalid proposal configuration
|
|
#[error("Invalid proposal: {message}")]
|
|
InvalidProposal { message: String },
|
|
|
|
/// Performance validation failed
|
|
#[error("Performance validation failed: expected {expected}, got {actual}")]
|
|
PerformanceValidationFailed { expected: f32, actual: f32 },
|
|
|
|
/// Rollback operation failed
|
|
#[error("Rollback failed: {reason}")]
|
|
RollbackFailed { reason: String },
|
|
|
|
/// Checkpoint not found
|
|
#[error("Checkpoint not found: {id}")]
|
|
CheckpointNotFound { id: String },
|
|
|
|
/// Agent initialization failed
|
|
#[error("Agent initialization failed: {agent_type}")]
|
|
AgentInitializationFailed { agent_type: String },
|
|
|
|
/// Configuration error
|
|
#[error("Configuration error: {message}")]
|
|
Configuration { message: String },
|
|
|
|
/// Serialization/deserialization error
|
|
#[error("Serialization error: {0}")]
|
|
Serialization(#[from] serde_json::Error),
|
|
|
|
/// I/O operation error
|
|
#[error("I/O error: {0}")]
|
|
Io(#[from] std::io::Error),
|
|
|
|
/// Concurrent operation error
|
|
#[error("Concurrency error: {message}")]
|
|
Concurrency { message: String },
|
|
|
|
/// Resource exhaustion error
|
|
#[error("Resource exhausted: {resource}")]
|
|
ResourceExhausted { resource: String },
|
|
|
|
/// Optimization conflict detected
|
|
#[error("Optimization conflict: {details}")]
|
|
OptimizationConflict { details: String },
|
|
}
|
|
|
|
/// Result type for autonomous optimization operations.
|
|
pub type AutoResult<T> = Result<T, AutoError>;
|
|
|
|
impl AutoError {
|
|
/// Create a new invalid proposal error.
|
|
pub fn invalid_proposal<S: Into<String>>(message: S) -> Self {
|
|
Self::InvalidProposal {
|
|
message: message.into(),
|
|
}
|
|
}
|
|
|
|
/// Create a new performance validation failed error.
|
|
pub fn performance_validation_failed(expected: f32, actual: f32) -> Self {
|
|
Self::PerformanceValidationFailed { expected, actual }
|
|
}
|
|
|
|
/// Create a new rollback failed error.
|
|
pub fn rollback_failed<S: Into<String>>(reason: S) -> Self {
|
|
Self::RollbackFailed {
|
|
reason: reason.into(),
|
|
}
|
|
}
|
|
|
|
/// Create a new checkpoint not found error.
|
|
pub fn checkpoint_not_found<S: Into<String>>(id: S) -> Self {
|
|
Self::CheckpointNotFound { id: id.into() }
|
|
}
|
|
|
|
/// Create a new agent initialization failed error.
|
|
pub fn agent_initialization_failed<S: Into<String>>(agent_type: S) -> Self {
|
|
Self::AgentInitializationFailed {
|
|
agent_type: agent_type.into(),
|
|
}
|
|
}
|
|
|
|
/// Create a new configuration error.
|
|
pub fn configuration<S: Into<String>>(message: S) -> Self {
|
|
Self::Configuration {
|
|
message: message.into(),
|
|
}
|
|
}
|
|
|
|
/// Create a new concurrency error.
|
|
pub fn concurrency<S: Into<String>>(message: S) -> Self {
|
|
Self::Concurrency {
|
|
message: message.into(),
|
|
}
|
|
}
|
|
|
|
/// Create a new resource exhausted error.
|
|
pub fn resource_exhausted<S: Into<String>>(resource: S) -> Self {
|
|
Self::ResourceExhausted {
|
|
resource: resource.into(),
|
|
}
|
|
}
|
|
|
|
/// Create a new optimization conflict error.
|
|
pub fn optimization_conflict<S: Into<String>>(details: S) -> Self {
|
|
Self::OptimizationConflict {
|
|
details: details.into(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_error_creation() {
|
|
let err = AutoError::invalid_proposal("Test proposal error");
|
|
assert!(matches!(err, AutoError::InvalidProposal { .. }));
|
|
|
|
let err = AutoError::performance_validation_failed(2.0, 1.5);
|
|
assert!(matches!(err, AutoError::PerformanceValidationFailed { .. }));
|
|
}
|
|
|
|
#[test]
|
|
fn test_error_display() {
|
|
let err = AutoError::invalid_proposal("Invalid configuration");
|
|
let error_msg = format!("{}", err);
|
|
assert!(error_msg.contains("Invalid proposal"));
|
|
assert!(error_msg.contains("Invalid configuration"));
|
|
}
|
|
}
|