use thiserror::Error;
use crate::state::StateError;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum ObservationError {
#[error("an observation plan must declare at least one observation stream")]
EmptyPlan,
#[error("observation stream name must not be empty")]
EmptyStreamName,
#[error("observation stream `{stream}` is declared more than once")]
DuplicateStreamName {
stream: String,
},
#[error("observation stream `{stream}` contains an empty field name")]
EmptyFieldName {
stream: String,
},
#[error("observation stream `{stream}` must select at least one state field")]
EmptyFieldSelection {
stream: String,
},
#[error("observation stream `{stream}` selects field `{field}` more than once")]
DuplicateField {
stream: String,
field: String,
},
#[error("observation stream `{stream}` selects unknown state field `{field}`")]
UnknownField {
stream: String,
field: String,
},
#[error("observation stream `{stream}` sampling interval must be greater than zero")]
InvalidSamplingInterval {
stream: String,
},
#[error("observation {axis} unit must not be empty")]
EmptyAxisUnit {
axis: &'static str,
},
#[error("state at iteration {iteration} does not share the observation-plan schema")]
SchemaMismatch {
iteration: u64,
},
#[error(
"cannot observe field `{field}` for stream `{stream}` at iteration {iteration}: {source}"
)]
StateAccess {
stream: String,
iteration: u64,
field: String,
#[source]
source: StateError,
},
#[error("failed to encode field `{field}` for stream `{stream}` at iteration {iteration}")]
EncodeField {
stream: String,
iteration: u64,
field: String,
#[source]
source: serde_json::Error,
},
#[error(
"observation stream `{stream}` observed iteration {next} after accepted iteration {previous}"
)]
NonIncreasingObservation {
stream: String,
previous: u64,
next: u64,
},
}