Skip to main content

scientific_workflow/reporting/
error.rs

1//! Errors produced by centralized progress registration and rendering.
2
3use std::io;
4
5use thiserror::Error;
6
7use crate::configuration::ConfigurationError;
8
9/// Failure while configuring, updating, or finalizing progress reporting.
10#[derive(Debug, Error)]
11#[non_exhaustive]
12pub enum ReportingError {
13    /// Project configuration could not supply a required task or identity value.
14    #[error(transparent)]
15    Configuration(#[from] ConfigurationError),
16
17    /// Another live reporter already owns process terminal rendering.
18    #[error("another progress reporter already owns the process terminal")]
19    TerminalAlreadyOwned,
20
21    /// The validated task count cannot be represented by this platform.
22    #[error("task count {task_count} exceeds this platform's addressable progress slots")]
23    TaskCountTooLarge {
24        /// Validated project task count.
25        task_count: u64,
26    },
27
28    /// One identity key was supplied more than once.
29    #[error("task identity repeats parameter key `{key}`")]
30    DuplicateIdentityParameter {
31        /// Repeated exact parameter name.
32        key: String,
33    },
34
35    /// One requested identity key is absent from project parameters.
36    #[error("task identity parameter `{key}` is not declared by the project")]
37    UnknownIdentityParameter {
38        /// Missing exact parameter name.
39        key: String,
40    },
41
42    /// Two generated tasks have the same selected parameter identity.
43    #[error(
44        "task identity `{identity}` is shared by ordinals {first_ordinal} and {second_ordinal}"
45    )]
46    NonUniqueTaskIdentity {
47        /// Deterministic rendered parameter identity.
48        identity: String,
49        /// First colliding automatically assigned ordinal.
50        first_ordinal: u64,
51        /// Second colliding automatically assigned ordinal.
52        second_ordinal: u64,
53    },
54
55    /// A task handle does not belong to the reporter's configured task space.
56    #[error("task ordinal {task_ordinal} is outside the reporter's task registry")]
57    UnknownTaskOrdinal {
58        /// Automatically assigned ordinal obtained from `TaskConfig`.
59        task_ordinal: u64,
60    },
61
62    /// A task handle's selected identity differs from the registered project.
63    #[error("task ordinal {task_ordinal} does not match its registered parameter identity")]
64    TaskIdentityMismatch {
65        /// Automatically assigned task ordinal.
66        task_ordinal: u64,
67    },
68
69    /// The same task was started more than once.
70    #[error("task `{identity}` has already started or reached a terminal status")]
71    TaskAlreadyStarted {
72        /// Human-readable parameter identity.
73        identity: String,
74    },
75
76    /// Initial progress lies beyond a known target.
77    #[error("task `{identity}` starts at iteration {initial}, beyond target {target}")]
78    InitialIterationBeyondTarget {
79        /// Human-readable parameter identity.
80        identity: String,
81        /// Initial absolute simulation iteration.
82        initial: u64,
83        /// Target absolute simulation iteration.
84        target: u64,
85    },
86
87    /// A progress update attempted to move scientific iteration backward.
88    #[error("task `{identity}` cannot move progress from iteration {current} back to {attempted}")]
89    IterationRegressed {
90        /// Human-readable parameter identity.
91        identity: String,
92        /// Previously reported iteration.
93        current: u64,
94        /// Rejected iteration.
95        attempted: u64,
96    },
97
98    /// A progress update exceeded a known target.
99    #[error("task `{identity}` reported iteration {iteration}, beyond target {target}")]
100    IterationBeyondTarget {
101        /// Human-readable parameter identity.
102        identity: String,
103        /// Rejected absolute simulation iteration.
104        iteration: u64,
105        /// Configured absolute target iteration.
106        target: u64,
107    },
108
109    /// Completion was requested before a known target was reached.
110    #[error("task `{identity}` completed at iteration {current}, before target {target}")]
111    TargetIterationNotReached {
112        /// Human-readable parameter identity.
113        identity: String,
114        /// Last reported absolute simulation iteration.
115        current: u64,
116        /// Configured absolute target iteration.
117        target: u64,
118    },
119
120    /// The sole renderer thread could not be created.
121    #[error("failed to start the centralized terminal reporter")]
122    StartRenderer {
123        /// Underlying thread-creation failure.
124        #[source]
125        source: io::Error,
126    },
127
128    /// The renderer stopped before accepting a requested message.
129    #[error("the centralized terminal reporter is no longer available")]
130    RendererUnavailable,
131
132    /// The renderer thread panicked while the reporter was active.
133    #[error("the centralized terminal reporter panicked")]
134    RendererPanicked,
135
136    /// Successful finalization was requested before every task completed.
137    #[error(
138        "cannot report success with {pending} pending, {running} running, and {failed} failed tasks"
139    )]
140    IncompleteProgress {
141        /// Tasks that never started.
142        pending: u64,
143        /// Tasks that have not reached a terminal status.
144        running: u64,
145        /// Tasks that failed or dropped before completion.
146        failed: u64,
147    },
148}