use xtce_model::{ContainerId, ParamId};
use crate::bits::BitError;
#[derive(Clone, Debug, thiserror::Error)]
#[non_exhaustive]
pub enum DecodeError {
#[error("{parameter}: {source}")]
Bits {
parameter: String,
#[source]
source: BitError,
},
#[error("no container named {name:?}")]
NoSuchContainer {
name: String,
},
#[error(
"no root container could be chosen automatically ({candidates} candidates); name one explicitly"
)]
AmbiguousRoot {
candidates: usize,
},
#[error("packet not recognised: abstract container {container} has no matching inheritor")]
UnrecognizedPacket {
container: String,
candidates: Vec<String>,
},
#[error("ambiguous packet type: {} inheritors of {container} all match", .candidates.len())]
AmbiguousPacket {
container: String,
candidates: Vec<String>,
},
#[error("{context} references parameter {parameter:?}, which has not been decoded yet")]
ParameterNotYetDecoded {
context: &'static str,
parameter: String,
},
#[error("cannot compare {parameter} ({value_kind}) against literal {literal:?}")]
IncomparableValue {
parameter: String,
value_kind: &'static str,
literal: String,
},
#[error("{parameter}: {bytes} byte(s) are not valid {charset}")]
InvalidText {
parameter: String,
charset: &'static str,
bytes: usize,
},
#[error("{parameter}: termination character not found in the {bytes}-byte string buffer")]
UnterminatedString {
parameter: String,
bytes: usize,
},
#[error("{parameter}: raw value {value} is not in the enumeration")]
UnknownEnumeration {
parameter: String,
value: i128,
},
#[error("{parameter}: {reason}")]
Calibration {
parameter: String,
reason: String,
},
#[error("{parameter}: computed field size {bits} bits is not usable")]
BadFieldSize {
parameter: String,
bits: i64,
},
#[error("{parameter}: no discrete lookup matched")]
NoDiscreteLookupMatch {
parameter: String,
},
#[error("unsupported XTCE construct <{element}> reached while decoding {context}")]
Unsupported {
element: String,
context: String,
},
#[error("internal: {what} index does not resolve")]
DanglingIndex {
what: &'static str,
},
}
impl DecodeError {
pub(crate) fn dangling_parameter(_id: ParamId) -> Self {
Self::DanglingIndex { what: "parameter" }
}
pub(crate) fn dangling_container(_id: ContainerId) -> Self {
Self::DanglingIndex { what: "container" }
}
}