Initial commit
This commit is contained in:
@@ -0,0 +1,168 @@
|
||||
//! Error types for neuro IPC commands.
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
/// Error type for neuro IPC commands
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct NeuroError {
|
||||
/// Error message
|
||||
pub message: String,
|
||||
/// Error code
|
||||
pub code: String,
|
||||
}
|
||||
|
||||
impl From<rtx_neuro::NeuroError> for NeuroError {
|
||||
fn from(err: rtx_neuro::NeuroError) -> Self {
|
||||
Self {
|
||||
message: err.to_string(),
|
||||
code: "NEURO_ERROR".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for NeuroError {
|
||||
fn from(err: std::io::Error) -> Self {
|
||||
Self {
|
||||
message: err.to_string(),
|
||||
code: "IO_ERROR".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<rtx_neuro::io::IoError> for NeuroError {
|
||||
fn from(err: rtx_neuro::io::IoError) -> Self {
|
||||
Self {
|
||||
message: err.to_string(),
|
||||
code: "IO_ERROR".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<rtx_neuro::signal::SignalError> for NeuroError {
|
||||
fn from(err: rtx_neuro::signal::SignalError) -> Self {
|
||||
Self {
|
||||
message: err.to_string(),
|
||||
code: "SIGNAL_ERROR".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<rtx_neuro_forward::ForwardError> for NeuroError {
|
||||
fn from(err: rtx_neuro_forward::ForwardError) -> Self {
|
||||
Self {
|
||||
message: err.to_string(),
|
||||
code: "FORWARD_ERROR".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<rtx_neuro_inverse::InverseError> for NeuroError {
|
||||
fn from(err: rtx_neuro_inverse::InverseError) -> Self {
|
||||
Self {
|
||||
message: err.to_string(),
|
||||
code: "INVERSE_ERROR".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<rtx_neuro_connectivity::ConnectivityError> for NeuroError {
|
||||
fn from(err: rtx_neuro_connectivity::ConnectivityError) -> Self {
|
||||
Self {
|
||||
message: err.to_string(),
|
||||
code: "CONNECTIVITY_ERROR".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<rtx_neuro_fem::FemError> for NeuroError {
|
||||
fn from(err: rtx_neuro_fem::FemError) -> Self {
|
||||
Self {
|
||||
message: err.to_string(),
|
||||
code: "FEM_ERROR".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<rtx_neuro_lsl::LslError> for NeuroError {
|
||||
fn from(err: rtx_neuro_lsl::LslError) -> Self {
|
||||
Self {
|
||||
message: err.to_string(),
|
||||
code: "LSL_ERROR".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<rtx_neuro_db::DatabaseError> for NeuroError {
|
||||
fn from(err: rtx_neuro_db::DatabaseError) -> Self {
|
||||
Self {
|
||||
message: err.to_string(),
|
||||
code: "DATABASE_ERROR".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl NeuroError {
|
||||
/// Create a FEM error
|
||||
pub fn fem_error(msg: impl Into<String>) -> Self {
|
||||
Self {
|
||||
message: msg.into(),
|
||||
code: "FEM_ERROR".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a not found error
|
||||
pub fn not_found(msg: impl Into<String>) -> Self {
|
||||
Self {
|
||||
message: msg.into(),
|
||||
code: "NOT_FOUND".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a BCI error
|
||||
pub fn bci_error(msg: impl Into<String>) -> Self {
|
||||
Self {
|
||||
message: msg.into(),
|
||||
code: "BCI_ERROR".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a GNN error
|
||||
pub fn gnn_error(msg: impl Into<String>) -> Self {
|
||||
Self {
|
||||
message: msg.into(),
|
||||
code: "GNN_ERROR".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a detector not initialized error
|
||||
pub fn detector_not_init() -> Self {
|
||||
Self {
|
||||
message: "Artifact detector not initialized".to_string(),
|
||||
code: "DETECTOR_NOT_INIT".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a BCI not created error
|
||||
pub fn bci_not_created() -> Self {
|
||||
Self {
|
||||
message: "BCI pipeline not created".to_string(),
|
||||
code: "BCI_NOT_CREATED".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a PINN error
|
||||
pub fn pinn_error(msg: impl Into<String>) -> Self {
|
||||
Self {
|
||||
message: msg.into(),
|
||||
code: "PINN_ERROR".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a stats error
|
||||
pub fn stats_error(msg: impl Into<String>) -> Self {
|
||||
Self {
|
||||
message: msg.into(),
|
||||
code: "STATS_ERROR".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user