Skip to main content

prompter/
error.rs

1//! Error types for the prompter crate.
2
3use crate::profile::ResolveError;
4use std::path::PathBuf;
5
6/// All errors that can occur during prompter configuration loading, profile
7/// resolution, rendering, and scaffolding.
8///
9/// Each variant names a distinct failure mode a caller might branch on.
10/// Variants that carry a bare `String` do so only for human-facing context
11/// (a library/serializer message, a clap usage string) that callers merely
12/// display rather than match on.
13#[derive(thiserror::Error, Debug)]
14pub enum PrompterError {
15    /// An I/O operation failed, annotated with the path it concerned.
16    #[error("Failed to access {path}: {source}")]
17    Io {
18        /// The filesystem path the failing operation targeted.
19        path: PathBuf,
20        /// The underlying I/O error.
21        source: std::io::Error,
22    },
23
24    /// A write to an output sink failed.
25    #[error("Write error: {0}")]
26    Write(std::io::Error),
27
28    /// The home directory could not be located (`$HOME` unset).
29    #[error("$HOME not set")]
30    HomeNotSet,
31
32    /// The current working directory could not be resolved.
33    #[error("Failed to resolve working directory: {0}")]
34    WorkingDir(std::io::Error),
35
36    /// A config file path lacked a parent directory.
37    #[error("Config path {0} has no parent directory")]
38    NoParentDir(PathBuf),
39
40    /// The TOML in a config file was syntactically invalid.
41    #[error("Invalid TOML: {0}")]
42    InvalidToml(#[from] toml::de::Error),
43
44    /// A reserved top-level config field had the wrong type or shape.
45    #[error("{0}")]
46    ConfigField(String),
47
48    /// A profile name was defined more than once across the merged bundle.
49    #[error("{0}")]
50    DuplicateProfile(String),
51
52    /// An `import` chain referred back to a config file already being loaded.
53    #[error("Import cycle detected at {0}")]
54    ImportCycle(PathBuf),
55
56    /// A profile dependency could not be resolved.
57    #[error(transparent)]
58    Resolve(#[from] ResolveError),
59
60    /// Validation found one or more problems; the message aggregates them.
61    #[error("{0}")]
62    Validation(String),
63
64    /// A value could not be serialized to JSON.
65    #[error("JSON serialization error: {0}")]
66    Json(#[from] serde_json::Error),
67
68    /// Command-line arguments could not be parsed; the payload is clap's
69    /// formatted usage/error text, shown to the user verbatim.
70    #[error("{0}")]
71    ArgParse(String),
72}