use std::fmt;
use std::io;
use semver::Version;
use thiserror::Error;
#[derive(Debug)]
pub struct NameList(pub Vec<String>);
impl fmt::Display for NameList {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0.join(", "))
}
}
#[derive(Debug, Error)]
pub enum TemplateError {
#[error("invalid template manifest: {0}")]
InvalidManifest(String),
#[error("I/O error: {0}")]
Io(#[from] io::Error),
#[error("no templates found in {0}")]
NoTemplatesFound(String),
#[error("template '{name}' not found, available: {available}")]
TemplateNotFound {
name: String,
available: NameList,
},
#[error("destination already exists: {0}")]
AlreadyInstalled(String),
#[error("duplicate template name '{name}': found in '{first}' and '{second}'")]
DuplicateName {
name: String,
first: String,
second: String,
},
#[error("git error: {0}")]
Git(String),
#[error("template requires Ironflow >= {template_min}, project has {project_version}")]
VersionIncompatible {
template_min: Version,
project_version: Version,
},
#[error("registry error: {0}")]
Registry(String),
#[error("registry not found at {url}: {reason}")]
RegistryNotFound {
url: String,
reason: String,
},
#[error("registry unreachable at {url}: {reason}")]
RegistryUnreachable {
url: String,
reason: String,
},
#[error("no tags found in repository: {0}")]
NoTagsFound(String),
#[error("lockfile error: {0}")]
Lockfile(String),
#[error("template '{name}' not found in registry, available: {available}")]
NotInRegistry {
name: String,
available: NameList,
},
#[error("invalid version: {0}")]
InvalidVersion(String),
}