1use std::io;
4
5#[derive(Debug, thiserror::Error)]
7pub enum InputError {
8 #[error("No editor found. Set VISUAL or EDITOR environment variable.")]
10 NoEditor,
11
12 #[error("Editor cancelled without saving.")]
14 EditorCancelled,
15
16 #[error("Editor failed: {0}")]
18 EditorFailed(#[source] io::Error),
19
20 #[error("Failed to read stdin: {0}")]
22 StdinFailed(#[source] io::Error),
23
24 #[error("Failed to read clipboard: {0}")]
26 ClipboardFailed(String),
27
28 #[error("Prompt cancelled by user.")]
30 PromptCancelled,
31
32 #[error("Prompt failed: {0}")]
34 PromptFailed(String),
35
36 #[error("Validation failed: {0}")]
38 ValidationFailed(String),
39
40 #[error("No input provided and no default available.")]
42 NoInput,
43
44 #[error("Required argument '{0}' not provided.")]
46 MissingArgument(String),
47
48 #[error("Failed to parse argument '{name}': {reason}")]
50 ParseError { name: String, reason: String },
51}
52
53impl InputError {
54 pub fn validation(msg: impl Into<String>) -> Self {
56 Self::ValidationFailed(msg.into())
57 }
58
59 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}