Skip to main content

muster/adapter/cli/
error.rs

1use thiserror::Error;
2
3use crate::domain::config::ConfigError;
4
5/// A failure while executing a CLI command.
6#[derive(Debug, Error)]
7pub enum CliError {
8    /// No registered project matched the requested name.
9    #[error("unknown project '{0}'")]
10    UnknownProject(String),
11    /// The derived or given process name was empty.
12    #[error("'{0}' is not a valid process name")]
13    InvalidName(String),
14    /// The command was blank.
15    #[error("the command is empty")]
16    EmptyCommand,
17    /// The command could not be reassembled into a shell string.
18    #[error("the command cannot be represented as a shell command")]
19    InvalidCommand,
20    /// `muster run` is not available on this platform.
21    #[error("muster run is only supported on Unix")]
22    Unsupported,
23    /// The workspace file could not be read or written.
24    #[error(transparent)]
25    Config(#[from] ConfigError),
26    /// The command could not be executed.
27    #[error("failed to run the command: {0}")]
28    Exec(#[source] std::io::Error),
29    /// The path cannot be stored in the registry (not valid UTF-8).
30    #[error("'{0}' contains non-UTF-8 components and cannot be registered")]
31    UnrepresentablePath(std::path::PathBuf),
32    /// The folder name could not become a project name.
33    #[error("cannot derive a project name from '{0}'")]
34    InvalidProjectFolder(std::path::PathBuf),
35    /// The folder has no workspace file to register.
36    #[error("{0} not found; run `muster init` there first")]
37    MissingWorkspaceFile(std::path::PathBuf),
38    /// No registered project matched, listing what exists.
39    #[error("unknown project '{name}'; registered: {known}")]
40    UnknownProjectAmong { name: String, known: String },
41    /// More than one registered project has the requested name.
42    #[error("'{name}' matches {count} projects; remove is ambiguous. Registered paths: {paths}")]
43    AmbiguousProject {
44        /// The name that matched multiple projects.
45        name: String,
46        /// How many projects matched.
47        count: usize,
48        /// The config paths of the matching projects, joined by ", ".
49        paths: String,
50    },
51}