rtb_tui/error.rs
1//! [`WizardError`] and [`RenderError`].
2
3/// Failure modes for [`crate::Wizard`].
4///
5/// `Clone` is derived so callers can route errors through retry
6/// pipelines or attach them to telemetry events without losing detail.
7#[derive(Debug, thiserror::Error, miette::Diagnostic, Clone)]
8#[non_exhaustive]
9pub enum WizardError {
10 /// User escaped out of the first step. Distinct from
11 /// [`Self::Interrupted`] — explicit cancel, not Ctrl+C.
12 #[error("wizard cancelled")]
13 #[diagnostic(code(rtb::tui::wizard_cancelled))]
14 Cancelled,
15
16 /// Ctrl+C (terminal SIGINT). Surfaced verbatim so callers can
17 /// translate to a process exit code.
18 #[error("wizard interrupted (Ctrl+C)")]
19 #[diagnostic(code(rtb::tui::wizard_interrupted))]
20 Interrupted,
21
22 /// A step's `prompt` returned an [`inquire::InquireError`] that
23 /// the wizard driver couldn't map to back-navigation.
24 #[error("wizard step `{step}` failed: {message}")]
25 #[diagnostic(code(rtb::tui::wizard_step))]
26 Step {
27 /// Name of the step that failed (from `WizardStep::name`).
28 step: String,
29 /// Stringified message from the underlying `InquireError`.
30 message: String,
31 },
32}
33
34/// Failure modes for [`crate::render_json`].
35///
36/// `render_table` is infallible (no failure modes for `tabled` over
37/// a `Tabled`-deriving type), so the only render error today is
38/// JSON serialisation.
39#[derive(Debug, thiserror::Error, miette::Diagnostic, Clone)]
40#[non_exhaustive]
41pub enum RenderError {
42 /// `serde_json` rejected one of the rows. Always programmer
43 /// mistake (non-`Serialize`-clean data structure), never user
44 /// input — the payload is pre-stringified for that reason.
45 #[error("JSON serialisation failed: {0}")]
46 #[diagnostic(code(rtb::tui::render_json))]
47 Json(String),
48}