Skip to main content

callisto_cli/
error.rs

1use callisto_graph::locate::LocateError;
2use callisto_graph::{ConfigError, GraphError};
3use callisto_model::CommandError;
4use miette::Diagnostic;
5
6#[derive(Debug, thiserror::Error, Diagnostic)]
7#[non_exhaustive]
8pub enum CliError {
9    #[error(transparent)]
10    #[diagnostic(transparent)]
11    Graph(#[from] GraphError),
12
13    #[error(transparent)]
14    #[diagnostic(transparent)]
15    Locate(#[from] LocateError),
16
17    #[error(transparent)]
18    #[diagnostic(transparent)]
19    Config(#[from] ConfigError),
20
21    #[error(transparent)]
22    #[diagnostic(transparent)]
23    Command(#[from] CommandError),
24
25    #[error(transparent)]
26    #[diagnostic(
27        code(callisto::registry_error),
28        help("verify registry credentials/authentication and network connectivity, then retry")
29    )]
30    Registry(#[from] callisto_model::RegistryError),
31
32    #[error(transparent)]
33    #[diagnostic(transparent)]
34    ChangesetParse(#[from] callisto_format::ParseError),
35
36    #[error(transparent)]
37    #[diagnostic(transparent)]
38    ChangesetWrite(#[from] callisto_format::WriteError),
39
40    #[error(transparent)]
41    #[diagnostic(transparent)]
42    Manifest(#[from] callisto_model::ManifestError),
43
44    #[error(transparent)]
45    #[diagnostic(transparent)]
46    Vcs(#[from] callisto_vcs::VcsError),
47
48    #[error(transparent)]
49    #[diagnostic(code(callisto::pre_json_error))]
50    PreJson(#[from] callisto_format::PreJsonError),
51
52    #[error("I/O error{}", match &path {
53        Some(p) => format!(" accessing `{}`", p.display()),
54        None => String::new(),
55    })]
56    #[diagnostic(
57        code(callisto::io_error),
58        help("check that the path exists and that you have permission to access it")
59    )]
60    Io {
61        #[source]
62        source: std::io::Error,
63        path: Option<std::path::PathBuf>,
64    },
65
66    #[error(
67        "refusing to prompt interactively: stdin is not a terminal and no non-interactive flags were given"
68    )]
69    #[diagnostic(
70        code(callisto::not_a_tty),
71        help("specify package names explicitly via `callisto add --package <name>:<severity>` in CI environments")
72    )]
73    NotATty,
74
75    #[error("{0}")]
76    #[diagnostic(code(callisto::error))]
77    Other(String),
78}
79
80impl From<std::io::Error> for CliError {
81    fn from(source: std::io::Error) -> Self {
82        CliError::Io { source, path: None }
83    }
84}