1use std::fmt;
2use std::io;
3
4#[derive(Debug)]
6pub enum BunCliError {
7 Io(io::Error),
9 CommandFailed { command: String, message: String },
11 InvalidProjectName(String),
13 BunNotInstalled,
15 TemplateCopyFailed(String),
17 DependencyFailed { dependency: String, message: String },
19}
20
21impl fmt::Display for BunCliError {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 match self {
24 BunCliError::Io(err) => write!(f, "IO error: {}", err),
25 BunCliError::CommandFailed { command, message } => {
26 write!(f, "Command '{}' failed: {}", command, message)
27 }
28 BunCliError::InvalidProjectName(name) => {
29 write!(f, "Invalid project name '{}': must not be empty and should contain only valid characters", name)
30 }
31 BunCliError::BunNotInstalled => {
32 write!(f, "Bun is not installed. Please install Bun globally from https://bun.sh")
33 }
34 BunCliError::TemplateCopyFailed(message) => {
35 write!(f, "Failed to copy templates: {}", message)
36 }
37 BunCliError::DependencyFailed { dependency, message } => {
38 write!(f, "Failed to install dependency '{}': {}", dependency, message)
39 }
40 }
41 }
42}
43
44impl std::error::Error for BunCliError {
45 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
46 match self {
47 BunCliError::Io(err) => Some(err),
48 _ => None,
49 }
50 }
51}
52
53impl From<io::Error> for BunCliError {
54 fn from(err: io::Error) -> Self {
55 BunCliError::Io(err)
56 }
57}
58
59pub type Result<T> = std::result::Result<T, BunCliError>;