1use pyo3::PyErr;
2use thiserror::Error;
3
4#[derive(Error, Debug)]
5pub enum DPError {
6 #[error("An error occurred: {0}")]
7 Generic(String),
8
9 #[error("Another error occurred")]
10 Another,
11
12 #[error("The sequence is shorter than the k-mer size")]
13 SeqShorterThanKmer,
14
15 #[error("The target region is invalid")]
16 TargetRegionInvalid,
17
18 #[error("The k-mer id is invalid")]
19 InvalidKmerId,
20
21 #[error("The interval is invalid: {0}")]
22 InvalidInterval(String),
23
24 #[error("The sequence and quality scores have different lengths: {0}")]
25 NotSameLengthForQualityAndSequence(String),
26}
27
28impl From<DPError> for PyErr {
29 fn from(error: DPError) -> PyErr {
30 use DPError::*;
31 match error {
32 Generic(message) => pyo3::exceptions::PyException::new_err(message),
33 Another => pyo3::exceptions::PyException::new_err("Another error occurred"),
34 SeqShorterThanKmer => pyo3::exceptions::PyException::new_err(
35 "The sequence is shorter than the k-mer size",
36 ),
37 TargetRegionInvalid => {
38 pyo3::exceptions::PyException::new_err("The target region is invalid")
39 }
40 InvalidKmerId => pyo3::exceptions::PyException::new_err("The k-mer id is invalid"),
41 InvalidInterval(interval) => pyo3::exceptions::PyException::new_err(format!(
42 "The interval is invalid: {:?}",
43 interval
44 )),
45 NotSameLengthForQualityAndSequence(mes) => {
46 pyo3::exceptions::PyException::new_err(format!(
47 "The sequence and quality scores have different lengths: {:?}",
48 mes
49 ))
50 }
51 }
52 }
53}