scientific_workflow/observation/error.rs
1//! Observation declaration, binding, and encoding failures.
2
3use thiserror::Error;
4
5use crate::state::StateError;
6
7/// A failure while defining, binding, or applying a scientific observation plan.
8#[derive(Debug, Error)]
9#[non_exhaustive]
10pub enum ObservationError {
11 /// A multi-stream observation plan contained no streams.
12 #[error("an observation plan must declare at least one observation stream")]
13 EmptyPlan,
14
15 /// A stream name normalized to an empty value.
16 #[error("observation stream name must not be empty")]
17 EmptyStreamName,
18
19 /// Two streams used the same normalized scientific name.
20 #[error("observation stream `{stream}` is declared more than once")]
21 DuplicateStreamName {
22 /// Repeated stream name.
23 stream: String,
24 },
25
26 /// A selected field name normalized to an empty value.
27 #[error("observation stream `{stream}` contains an empty field name")]
28 EmptyFieldName {
29 /// Stream containing the invalid selection.
30 stream: String,
31 },
32
33 /// A stream selected no fields.
34 #[error("observation stream `{stream}` must select at least one state field")]
35 EmptyFieldSelection {
36 /// Stream with no selected fields.
37 stream: String,
38 },
39
40 /// A stream selected one normalized field more than once.
41 #[error("observation stream `{stream}` selects field `{field}` more than once")]
42 DuplicateField {
43 /// Stream containing the duplicate selection.
44 stream: String,
45 /// Repeated field name.
46 field: String,
47 },
48
49 /// A stream selected a field absent from the bound state schema.
50 #[error("observation stream `{stream}` selects unknown state field `{field}`")]
51 UnknownField {
52 /// Stream containing the unknown selection.
53 stream: String,
54 /// Unknown field name.
55 field: String,
56 },
57
58 /// An iteration sampling interval was zero.
59 #[error("observation stream `{stream}` sampling interval must be greater than zero")]
60 InvalidSamplingInterval {
61 /// Stream receiving the invalid interval.
62 stream: String,
63 },
64
65 /// A scientific axis unit normalized to an empty value.
66 #[error("observation {axis} unit must not be empty")]
67 EmptyAxisUnit {
68 /// Stable axis name: `iteration` or `physical_time`.
69 axis: &'static str,
70 },
71
72 /// An observation did not share the descriptor's schema allocation.
73 #[error("state at iteration {iteration} does not share the observation-plan schema")]
74 SchemaMismatch {
75 /// Iteration carried by the rejected observation.
76 iteration: u64,
77 },
78
79 /// A selected payload could not be borrowed from the observed state.
80 #[error(
81 "cannot observe field `{field}` for stream `{stream}` at iteration {iteration}: {source}"
82 )]
83 StateAccess {
84 /// Stream being encoded.
85 stream: String,
86 /// State iteration being observed.
87 iteration: u64,
88 /// Selected field that could not be borrowed.
89 field: String,
90 /// Original typed state-access failure.
91 #[source]
92 source: StateError,
93 },
94
95 /// Serde rejected a selected scientific payload.
96 #[error("failed to encode field `{field}` for stream `{stream}` at iteration {iteration}")]
97 EncodeField {
98 /// Stream being encoded.
99 stream: String,
100 /// State iteration being observed.
101 iteration: u64,
102 /// Field active when encoding failed.
103 field: String,
104 /// Original JSON serialization failure.
105 #[source]
106 source: serde_json::Error,
107 },
108
109 /// A state observation moved backward relative to an accepted stream value.
110 #[error(
111 "observation stream `{stream}` observed iteration {next} after accepted iteration {previous}"
112 )]
113 NonIncreasingObservation {
114 /// Stream whose ordering would be violated.
115 stream: String,
116 /// Most recently accepted iteration.
117 previous: u64,
118 /// Rejected decreasing iteration.
119 next: u64,
120 },
121}