1use anyhow::Error as AnyhowError;
2
3#[derive(Debug, thiserror::Error)]
4#[error("{message}")]
5pub struct CliError {
6 message: String,
7 #[source]
8 source: Option<AnyhowError>,
9 hint: Option<String>,
10}
11
12impl CliError {
13 pub fn new(message: impl Into<String>) -> Self {
14 Self {
15 message: message.into(),
16 source: None,
17 hint: None,
18 }
19 }
20
21 pub fn with_source(message: impl Into<String>, source: impl Into<AnyhowError>) -> Self {
22 Self {
23 message: message.into(),
24 source: Some(source.into()),
25 hint: None,
26 }
27 }
28
29 pub fn with_hint(mut self, hint: impl Into<String>) -> Self {
30 self.hint = Some(hint.into());
31 self
32 }
33
34 pub fn hint(&self) -> Option<&str> {
35 self.hint.as_deref()
36 }
37
38 pub fn source_error(&self) -> Option<&AnyhowError> {
39 self.source.as_ref()
40 }
41}
42
43pub type Result<T> = std::result::Result<T, CliError>;