inquire/
error.rs

1//! Definitions of `inquire`'s error handling
2
3use std::io;
4
5use thiserror::Error;
6
7/// Type alias to define errors that might be thrown by the library user
8/// on callbacks such as validators.
9pub type CustomUserError = Box<dyn std::error::Error + Send + Sync + 'static>;
10
11/// Possible errors returned by `inquire` prompts.
12#[derive(Error, Debug)]
13pub enum InquireError {
14    /// The input device is not a TTY, which means that enabling raw mode
15    /// on the terminal in order to listen to input events is not possible.
16    #[error("The input device is not a TTY")]
17    NotTTY,
18
19    /// The given prompt configuration is not valid. A detailed error message
20    /// is contained in the value string.
21    #[error("The prompt configuration is invalid: {0}")]
22    InvalidConfiguration(String),
23
24    /// Error while executing IO operations.
25    #[error("IO error: {0}")]
26    IO(#[from] io::Error),
27
28    /// The user canceled the operation by pressing ESC.
29    #[error("Operation was canceled by the user")]
30    OperationCanceled,
31
32    /// The operation was interrupted by the user after they
33    /// pressed Ctrl+C.
34    ///
35    /// This error will be returned only when using `crossterm`
36    /// or `termion` as the terminal back-end. If using `console`,
37    /// pressing Ctrl+C will trigger SIGINT.
38    #[error("Operation was interrupted by the user")]
39    OperationInterrupted,
40
41    /// Error while executing IO operations.
42    #[error("User-provided error: {0}")]
43    Custom(#[from] CustomUserError),
44}
45
46/// Result type where errors are of type [InquireError](crate::error::InquireError)
47pub type InquireResult<T> = Result<T, InquireError>;