tf_binding_rs/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use std::io;
use thiserror::Error;

#[derive(Error, Debug)]
pub enum MotifError {
    #[error("IO error: {0}")]
    Io(#[from] io::Error),

    #[error("Invalid sequence at position {position}: {message}")]
    InvalidSequence { position: usize, message: String },

    #[error("Invalid PWM format: {0}")]
    InvalidPwm(String),

    #[error("Invalid file format: {0}")]
    InvalidFileFormat(String),

    #[error("Data error: {0}")]
    DataError(String),

    #[error("Invalid parameter: {name} = {value}, {message}")]
    InvalidParameter {
        name: String,
        value: String,
        message: String,
    },

    #[error("Invalid input: {0}")]
    InvalidInput(String),
}

// // Type alias for Result with MotifError
// pub type Result<T> = std::result::Result<T, MotifError>;

impl MotifError {
    /// Create a new InvalidSequence error
    pub fn invalid_sequence(position: usize, message: impl Into<String>) -> Self {
        MotifError::InvalidSequence {
            position,
            message: message.into(),
        }
    }

    /// Create a new InvalidPwm error
    pub fn invalid_pwm(message: impl Into<String>) -> Self {
        MotifError::InvalidPwm(message.into())
    }

    /// Create a new InvalidParameter error
    pub fn invalid_parameter(
        name: impl Into<String>,
        value: impl ToString,
        message: impl Into<String>,
    ) -> Self {
        MotifError::InvalidParameter {
            name: name.into(),
            value: value.to_string(),
            message: message.into(),
        }
    }
}