/
errors.rs
129 lines (107 loc) · 4.45 KB
/
errors.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
use thiserror::Error;
#[derive(Debug, Error)]
pub enum SourmashError {
/// Raised for internal errors in the libraries. Should not happen.
#[error("internal error: {message:?}")]
Internal { message: String },
#[error("must have same num: {n1} != {n2}")]
MismatchNum { n1: u32, n2: u32 },
#[error("different ksizes cannot be compared")]
MismatchKSizes,
#[error("DNA/prot minhashes cannot be compared")]
MismatchDNAProt,
#[error("mismatch in scaled; comparison fail")]
MismatchScaled,
#[error("mismatch in seed; comparison fail")]
MismatchSeed,
#[error("different signatures cannot be compared")]
MismatchSignatureType,
#[error("Invalid hash function: {function:?}")]
InvalidHashFunction { function: String },
#[error("Can only set {message:?} if the MinHash is empty")]
NonEmptyMinHash { message: String },
#[error("invalid DNA character in input k-mer: {message}")]
InvalidDNA { message: String },
#[error("invalid protein character in input: {message}")]
InvalidProt { message: String },
#[error("Codon is invalid length: {message}")]
InvalidCodonLength { message: String },
#[error("Set error rate to a value smaller than 0.367696 and larger than 0.00203125")]
HLLPrecisionBounds,
#[error(transparent)]
ReadDataError(#[from] crate::index::storage::ReadDataError),
#[error(transparent)]
StorageError(#[from] crate::index::storage::StorageError),
#[error(transparent)]
SerdeError(#[from] serde_json::error::Error),
#[error(transparent)]
NifflerError(#[from] niffler::Error),
#[error(transparent)]
Utf8Error(#[from] std::str::Utf8Error),
#[error(transparent)]
IOError(#[from] std::io::Error),
#[cfg(not(all(target_arch = "wasm32", target_vendor = "unknown")))]
#[error(transparent)]
Panic(#[from] crate::ffi::utils::Panic),
}
#[repr(u32)]
pub enum SourmashErrorCode {
// no error
NoError = 0,
// panics and internals
Panic = 1,
Internal = 2,
Msg = 3,
Unknown = 4,
// Compatibility errors
MismatchKSizes = 1_01,
MismatchDNAProt = 1_02,
MismatchScaled = 1_03,
MismatchSeed = 1_04,
MismatchSignatureType = 1_05,
NonEmptyMinHash = 1_06,
MismatchNum = 1_07,
// Input sequence errors
InvalidDNA = 11_01,
InvalidProt = 11_02,
InvalidCodonLength = 11_03,
InvalidHashFunction = 11_04,
// index-related errors
ReadData = 12_01,
Storage = 12_02,
// HLL errors
HLLPrecisionBounds = 13_01,
// external errors
Io = 100_001,
Utf8Error = 100_002,
ParseInt = 100_003,
SerdeError = 100_004,
NifflerError = 100_005,
}
#[cfg(not(all(target_arch = "wasm32", target_vendor = "unknown")))]
impl SourmashErrorCode {
pub fn from_error(error: &SourmashError) -> SourmashErrorCode {
match error {
SourmashError::Internal { .. } => SourmashErrorCode::Internal,
SourmashError::Panic { .. } => SourmashErrorCode::Panic,
SourmashError::MismatchNum { .. } => SourmashErrorCode::MismatchNum,
SourmashError::MismatchKSizes => SourmashErrorCode::MismatchKSizes,
SourmashError::MismatchDNAProt => SourmashErrorCode::MismatchDNAProt,
SourmashError::MismatchScaled => SourmashErrorCode::MismatchScaled,
SourmashError::MismatchSeed => SourmashErrorCode::MismatchSeed,
SourmashError::MismatchSignatureType => SourmashErrorCode::MismatchSignatureType,
SourmashError::NonEmptyMinHash { .. } => SourmashErrorCode::NonEmptyMinHash,
SourmashError::InvalidDNA { .. } => SourmashErrorCode::InvalidDNA,
SourmashError::InvalidProt { .. } => SourmashErrorCode::InvalidProt,
SourmashError::InvalidCodonLength { .. } => SourmashErrorCode::InvalidCodonLength,
SourmashError::InvalidHashFunction { .. } => SourmashErrorCode::InvalidHashFunction,
SourmashError::ReadDataError { .. } => SourmashErrorCode::ReadData,
SourmashError::StorageError { .. } => SourmashErrorCode::Storage,
SourmashError::HLLPrecisionBounds { .. } => SourmashErrorCode::HLLPrecisionBounds,
SourmashError::SerdeError { .. } => SourmashErrorCode::SerdeError,
SourmashError::IOError { .. } => SourmashErrorCode::Io,
SourmashError::NifflerError { .. } => SourmashErrorCode::NifflerError,
SourmashError::Utf8Error { .. } => SourmashErrorCode::Utf8Error,
}
}
}