use core::fmt;
pub type Result<T> = core::result::Result<T, Error>;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
EmptyAlphabet,
MatrixShape {
alphabet_len: usize,
expected: usize,
got: usize,
},
NegativeGapPenalty {
gap_open: i32,
gap_ext: i32,
},
GapOpenLessThanExtend {
gap_open: i32,
gap_ext: i32,
},
ScoreRangeTooWide {
bound: i64,
},
SymbolOutOfRange {
symbol: usize,
alphabet_len: usize,
},
IncompleteBuilder {
field: &'static str,
},
EmptyDatabase,
BackendUnavailable {
backend: crate::backend::Backend,
},
InvalidBackendName {
name: String,
},
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::EmptyAlphabet => write!(f, "alphabet length must be greater than zero"),
Error::MatrixShape {
alphabet_len,
expected,
got,
} => write!(
f,
"substitution matrix must have {expected} entries \
(alphabet_len {alphabet_len} squared), but got {got}"
),
Error::NegativeGapPenalty { gap_open, gap_ext } => write!(
f,
"gap penalties must be non-negative magnitudes, \
but got gap_open={gap_open}, gap_ext={gap_ext}"
),
Error::GapOpenLessThanExtend { gap_open, gap_ext } => write!(
f,
"gap_open ({gap_open}) must be >= gap_ext ({gap_ext}) (Opal issue #28)"
),
Error::ScoreRangeTooWide { bound } => write!(
f,
"reachable score magnitude bound ({bound}) exceeds the i32 range; \
reduce sequence lengths or penalty magnitudes"
),
Error::SymbolOutOfRange {
symbol,
alphabet_len,
} => write!(
f,
"encoded symbol {symbol} is out of range for alphabet_len {alphabet_len} \
(must be in 0..{alphabet_len})"
),
Error::IncompleteBuilder { field } => {
write!(f, "database builder is missing required field: {field}")
}
Error::EmptyDatabase => {
write!(f, "database must contain at least one sequence")
}
Error::BackendUnavailable { backend } => {
write!(f, "backend {backend} is not available on this build/CPU")
}
Error::InvalidBackendName { name } => write!(
f,
"unrecognised backend name {name:?}; expected one of: \
auto, scalar, sse4.1, avx2, neon"
),
}
}
}
impl core::error::Error for Error {}