use std::fmt;
use std::io;
#[derive(Debug)]
pub enum BunCliError {
Io(io::Error),
CommandFailed { command: String, message: String },
InvalidProjectName(String),
BunNotInstalled,
TemplateCopyFailed(String),
DependencyFailed { dependency: String, message: String },
}
impl fmt::Display for BunCliError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
BunCliError::Io(err) => write!(f, "IO error: {}", err),
BunCliError::CommandFailed { command, message } => {
write!(f, "Command '{}' failed: {}", command, message)
}
BunCliError::InvalidProjectName(name) => {
write!(f, "Invalid project name '{}': must not be empty and should contain only valid characters", name)
}
BunCliError::BunNotInstalled => {
write!(f, "Bun is not installed. Please install Bun globally from https://bun.sh")
}
BunCliError::TemplateCopyFailed(message) => {
write!(f, "Failed to copy templates: {}", message)
}
BunCliError::DependencyFailed { dependency, message } => {
write!(f, "Failed to install dependency '{}': {}", dependency, message)
}
}
}
}
impl std::error::Error for BunCliError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
BunCliError::Io(err) => Some(err),
_ => None,
}
}
}
impl From<io::Error> for BunCliError {
fn from(err: io::Error) -> Self {
BunCliError::Io(err)
}
}
pub type Result<T> = std::result::Result<T, BunCliError>;