Skip to main content

standout_input/
error.rs

1//! Error types for input collection.
2
3use std::io;
4
5/// Errors that can occur during input collection.
6#[derive(Debug, thiserror::Error)]
7pub enum InputError {
8    /// No editor found in environment.
9    #[error("No editor found. Set VISUAL or EDITOR environment variable.")]
10    NoEditor,
11
12    /// User cancelled the editor without saving.
13    #[error("Editor cancelled without saving.")]
14    EditorCancelled,
15
16    /// Editor process failed.
17    #[error("Editor failed: {0}")]
18    EditorFailed(#[source] io::Error),
19
20    /// Failed to read from stdin.
21    #[error("Failed to read stdin: {0}")]
22    StdinFailed(#[source] io::Error),
23
24    /// Failed to read from clipboard.
25    #[error("Failed to read clipboard: {0}")]
26    ClipboardFailed(String),
27
28    /// User cancelled an interactive prompt.
29    #[error("Prompt cancelled by user.")]
30    PromptCancelled,
31
32    /// Interactive prompt failed.
33    #[error("Prompt failed: {0}")]
34    PromptFailed(String),
35
36    /// Input validation failed.
37    #[error("Validation failed: {0}")]
38    ValidationFailed(String),
39
40    /// No input was provided and no default is available.
41    #[error("No input provided and no default available.")]
42    NoInput,
43
44    /// Required CLI argument was not provided.
45    #[error("Required argument '{0}' not provided.")]
46    MissingArgument(String),
47
48    /// Failed to parse argument value.
49    #[error("Failed to parse argument '{name}': {reason}")]
50    ParseError { name: String, reason: String },
51}
52
53impl InputError {
54    /// Create a validation error.
55    pub fn validation(msg: impl Into<String>) -> Self {
56        Self::ValidationFailed(msg.into())
57    }
58
59    /// Create a parse error.
60    pub fn parse(name: impl Into<String>, reason: impl Into<String>) -> Self {
61        Self::ParseError {
62            name: name.into(),
63            reason: reason.into(),
64        }
65    }
66}