tf_binding_rs/
error.rs

1use std::io;
2use thiserror::Error;
3
4#[derive(Error, Debug)]
5pub enum MotifError {
6    #[error("IO error: {0}")]
7    Io(#[from] io::Error),
8
9    #[error("Invalid sequence at position {position}: {message}")]
10    InvalidSequence { position: usize, message: String },
11
12    #[error("Invalid PWM format: {0}")]
13    InvalidPwm(String),
14
15    #[error("Invalid file format: {0}")]
16    InvalidFileFormat(String),
17
18    #[error("Data error: {0}")]
19    DataError(String),
20
21    #[error("Invalid parameter: {name} = {value}, {message}")]
22    InvalidParameter {
23        name: String,
24        value: String,
25        message: String,
26    },
27
28    #[error("Invalid input: {0}")]
29    InvalidInput(String),
30}
31
32// // Type alias for Result with MotifError
33// pub type Result<T> = std::result::Result<T, MotifError>;
34
35impl MotifError {
36    /// Create a new InvalidSequence error
37    pub fn invalid_sequence(position: usize, message: impl Into<String>) -> Self {
38        MotifError::InvalidSequence {
39            position,
40            message: message.into(),
41        }
42    }
43
44    /// Create a new InvalidPwm error
45    pub fn invalid_pwm(message: impl Into<String>) -> Self {
46        MotifError::InvalidPwm(message.into())
47    }
48
49    /// Create a new InvalidParameter error
50    pub fn invalid_parameter(
51        name: impl Into<String>,
52        value: impl ToString,
53        message: impl Into<String>,
54    ) -> Self {
55        MotifError::InvalidParameter {
56            name: name.into(),
57            value: value.to_string(),
58            message: message.into(),
59        }
60    }
61}