use crate::project::manifest::EnvironmentName;
use crate::task::TaskName;
use crate::Project;
use itertools::Itertools;
use miette::{Diagnostic, LabeledSpan};
use rattler_conda_types::Platform;
use std::error::Error;
use std::fmt::{Display, Formatter};
use thiserror::Error;
#[derive(Debug, Clone)]
pub struct UnsupportedPlatformError {
pub environments_platforms: Vec<Platform>,
pub environment: EnvironmentName,
pub platform: Platform,
}
impl Error for UnsupportedPlatformError {}
impl Display for UnsupportedPlatformError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match &self.environment {
EnvironmentName::Default => {
write!(f, "the project does not support '{}'", self.platform)
}
EnvironmentName::Named(name) => write!(
f,
"the environment '{}' does not support '{}'",
name, self.platform
),
}
}
}
impl Diagnostic for UnsupportedPlatformError {
fn code(&self) -> Option<Box<dyn Display + '_>> {
Some(Box::new("unsupported-platform".to_string()))
}
fn help(&self) -> Option<Box<dyn Display + '_>> {
Some(Box::new(format!(
"supported platforms are {}",
self.environments_platforms.iter().format(", ")
)))
}
fn labels(&self) -> Option<Box<dyn Iterator<Item = LabeledSpan> + '_>> {
None
}
}
#[derive(Debug, Clone, Diagnostic, Error)]
#[error("the task '{0}' could not be found", task_name.fancy_display())]
pub struct UnknownTask<'p> {
pub project: &'p Project,
pub environment: EnvironmentName,
pub platform: Option<Platform>,
pub task_name: TaskName,
}