#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DetectFailure {
NothingDetected,
PinnedNotInstalled {
family: String,
name: String,
},
PluginUnusable {
name: String,
problem: String,
},
UnknownPlugin {
name: String,
available: Vec<String>,
},
FamilyWithoutPlugin {
family: String,
score: u32,
},
}
impl DetectFailure {
pub fn message(&self) -> String {
match self {
DetectFailure::NothingDetected => "Cannot detect the project type.\n\
pmpx decides the project type from the detect files declared by installed plugins, so:\n\
- with no plugin installed, no project can be detected (`pmpx plugin add <name>`)\n\
- you can also declare it explicitly with a .pmpx.toml in the current directory, for example:\n\
[plugin]\n\
rust = \"cargo\""
.to_string(),
DetectFailure::FamilyWithoutPlugin { family, score } => format!(
"The winning family is {family} ({score} points), but no plugin belonging to it is installed.\n\
pmpx only knows which tool to invoke once one is installed."
),
DetectFailure::PinnedNotInstalled { family, name } => format!(
".pmpx.toml pins {family} to {name}, but it is not installed.\n\
Either install it (`pmpx plugin add {name}`) or change that pin."
),
DetectFailure::PluginUnusable { name, problem } => format!(
"{name} is installed but cannot take part in resolution: {problem}.\n\
Use `pmpx plugin ls` to see every plugin and its own problem."
),
DetectFailure::UnknownPlugin { name, available } => {
let mut msg = format!("Plugin {name} not found.");
if available.is_empty() {
msg.push_str("\nNo plugin is installed at all (`pmpx plugin add <name>`).");
} else {
msg.push_str("\nInstalled: ");
msg.push_str(&available.join(", "));
}
msg
}
}
}
}
impl From<DetectFailure> for crate::error::PmpxError {
fn from(f: DetectFailure) -> Self {
crate::error::PmpxError::NotFound(f.message())
}
}