98 lines
2.3 KiB
Rust
98 lines
2.3 KiB
Rust
//! Error types for real-time MEG/EEG processing.
|
|
|
|
use thiserror::Error;
|
|
|
|
/// Error type for real-time processing operations
|
|
#[derive(Error, Debug)]
|
|
pub enum RealtimeError {
|
|
/// Configuration error
|
|
#[error("Configuration error: {0}")]
|
|
Config(String),
|
|
|
|
/// Pipeline state error
|
|
#[error("Pipeline state error: {0}")]
|
|
PipelineState(String),
|
|
|
|
/// GPU computation error
|
|
#[error("GPU computation error: {0}")]
|
|
GpuComputation(String),
|
|
|
|
/// Filter design error
|
|
#[error("Filter design error: {0}")]
|
|
FilterDesign(String),
|
|
|
|
/// Beamformer error
|
|
#[error("Beamformer error: {0}")]
|
|
Beamformer(String),
|
|
|
|
/// LSL connection error
|
|
#[error("LSL connection error: {0}")]
|
|
LslConnection(String),
|
|
|
|
/// Buffer error
|
|
#[error("Buffer error: {0}")]
|
|
Buffer(String),
|
|
|
|
/// Dimension mismatch
|
|
#[error("Dimension mismatch: {0}")]
|
|
DimensionMismatch(String),
|
|
|
|
/// Latency violation
|
|
#[error("Latency violation: target {target_ms}ms, actual {actual_ms}ms")]
|
|
LatencyViolation {
|
|
/// Target latency in milliseconds
|
|
target_ms: f64,
|
|
/// Actual latency in milliseconds
|
|
actual_ms: f64,
|
|
},
|
|
|
|
/// Timeout error
|
|
#[error("Timeout: {0}")]
|
|
Timeout(String),
|
|
|
|
/// Channel closed
|
|
#[error("Channel closed: {0}")]
|
|
ChannelClosed(String),
|
|
|
|
/// Not initialized
|
|
#[error("Not initialized: {0}")]
|
|
NotInitialized(String),
|
|
|
|
/// Forward model error
|
|
#[error("Forward model error: {0}")]
|
|
ForwardModel(String),
|
|
|
|
/// Inverse operator error
|
|
#[error("Inverse operator error: {0}")]
|
|
InverseOperator(String),
|
|
|
|
/// IO error
|
|
#[error("IO error: {0}")]
|
|
Io(#[from] std::io::Error),
|
|
}
|
|
|
|
/// Result type for real-time operations
|
|
pub type RealtimeResult<T> = Result<T, RealtimeError>;
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_error_display() {
|
|
let err = RealtimeError::Config("Invalid sample rate".to_string());
|
|
assert!(err.to_string().contains("Invalid sample rate"));
|
|
}
|
|
|
|
#[test]
|
|
fn test_latency_violation_error() {
|
|
let err = RealtimeError::LatencyViolation {
|
|
target_ms: 10.0,
|
|
actual_ms: 25.0,
|
|
};
|
|
let msg = err.to_string();
|
|
assert!(msg.contains("target 10ms"));
|
|
assert!(msg.contains("actual 25ms"));
|
|
}
|
|
}
|