use thiserror::Error;
#[derive(Error, Debug)]
pub enum NewickError {
#[error("invalid character at byte {idx}")]
InvalidCharacter {
idx: usize,
},
#[error("unbalanced parentheses at byte {idx}")]
UnbalancedParens {
idx: usize,
},
#[error("unterminated quoted label starting at byte {idx}")]
UnterminatedQuote {
idx: usize,
},
#[error("unterminated comment starting at byte {idx}")]
UnterminatedComment {
idx: usize,
},
#[error("invalid branch length at byte {idx}: {text:?}")]
InvalidWeight {
idx: usize,
text: String,
},
#[error("invalid taxon label at byte {idx}: {text:?}")]
InvalidLabel {
idx: usize,
text: String,
},
#[error("empty input: no tree found")]
Empty,
}
#[derive(Error, Debug)]
pub enum NexusError {
#[error("expected \"#NEXUS\" at the start of the input")]
InvalidHeader,
#[error("no tree definition (expected a \"... = <newick>;\" entry in a TREES block)")]
MissingTreeBlock,
}
#[derive(Error, Debug, PartialEq, Eq, Clone)]
pub enum TreeError {
#[error("no node with id {0} in this tree")]
UnknownNode(usize),
#[error("expected at least one node id, got none")]
EmptyNodeSet,
#[error("({0}, {1}) is not an edge of this tree")]
UnknownEdge(usize, usize),
#[error("node {0} has no parent")]
NoParent(usize),
#[error("node {0} has no branch weight set")]
MissingWeight(usize),
#[error("node {0} has no zeta annotation set; call set_zeta first")]
MissingZeta(usize),
#[error("operation needs at least {expected} taxa, tree has {actual}")]
TooFewTaxa {
expected: usize,
actual: usize,
},
#[error("trees do not span the same taxa set")]
TaxaSetMismatch,
}
#[derive(Error, Debug)]
pub enum AsrError {
#[error("missing or non-positive branch length")]
MissingBranchLength,
#[error("alphabet mismatch: {0}")]
AlphabetMismatch(String),
#[error("invalid alignment: {0}")]
InvalidAlignment(String),
#[error("eigendecomposition failed to converge")]
EigendecompFailure,
#[error("numerical instability encountered during ASR scaling")]
NumericalInstability,
#[error("invalid model parameter: {0}")]
InvalidModelParameter(String),
}