use thiserror::Error;
#[derive(Error, Debug)]
pub enum ActrCliError {
#[error("IO operation failed: {0}")]
Io(#[from] std::io::Error),
#[error("Network request failed: {0}")]
Network(#[from] reqwest::Error),
#[error("JSON serialization failed: {0}")]
Serialization(#[from] serde_json::Error),
#[error("Git operation failed: {0}")]
Git(#[from] git2::Error),
#[error("Configuration error: {0}")]
Configuration(String),
#[error("Invalid project structure: {0}")]
InvalidProject(String),
#[error("Project already exists: {0}")]
ProjectExists(String),
#[error("Dependency resolution failed: {0}")]
Dependency(String),
#[error("Build process failed: {0}")]
Build(String),
#[error("Code generation failed: {0}")]
CodeGeneration(String),
#[error("Template rendering failed: {0}")]
Template(#[from] handlebars::RenderError),
#[error("Unsupported feature: {0}")]
Unsupported(String),
#[error("Command execution failed: {0}")]
Command(String),
#[error("Actor framework error: {0}")]
Actor(#[from] actr_protocol::ActrError),
#[error("Configuration parsing error: {0}")]
ConfigParsing(#[from] actr_config::ConfigError),
#[error("Internal error: {0}")]
Internal(#[from] anyhow::Error),
}
impl ActrCliError {
pub fn config_error(msg: impl Into<String>) -> Self {
Self::Configuration(msg.into())
}
pub fn dependency_error(msg: impl Into<String>) -> Self {
Self::Dependency(msg.into())
}
pub fn build_error(msg: impl Into<String>) -> Self {
Self::Build(msg.into())
}
pub fn command_error(msg: impl Into<String>) -> Self {
Self::Command(msg.into())
}
pub fn is_config_error(&self) -> bool {
matches!(
self,
Self::Configuration(_) | Self::ConfigParsing(_) | Self::InvalidProject(_)
)
}
pub fn is_network_error(&self) -> bool {
matches!(self, Self::Network(_))
}
pub fn user_hint(&self) -> Option<&str> {
match self {
Self::InvalidProject(_) => Some("💡 Use 'actr init' to initialize a new project"),
Self::ProjectExists(_) => Some("💡 Use --force to overwrite existing project"),
Self::Configuration(_) => Some("💡 Check your Actr.toml configuration file"),
Self::Dependency(_) => Some("💡 Try 'actr install --force' to refresh dependencies"),
Self::Build(_) => Some("💡 Check proto files and dependencies"),
Self::Network(_) => Some("💡 Check your network connection and proxy settings"),
Self::Unsupported(_) => Some("💡 This feature is not implemented yet"),
_ => None,
}
}
}
pub type Result<T> = std::result::Result<T, ActrCliError>;