use std::path::PathBuf;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum BuildError {
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("Failed to run command: {0}")]
Command(String),
#[error("Command `{cmd}` exited with code {code:?}")]
CommandFailed { cmd: String, code: Option<i32> },
#[error("Failed to compile {0}: {1}")]
Compile(String, String),
#[error("Compiler '{0}' not found.")]
CompilerNotFound(String),
#[error("Link error: {0}")]
Link(String),
#[error("No .c files found in src/")]
NoSourceFiles,
#[error("Failed to serialize TOML: {0}")]
TomlSer(#[from] toml::ser::Error),
#[error("Failed to parse TOML: {0}")]
TomlDe(#[from] toml::de::Error),
#[error("smidr.toml not found in {0}")]
ManifestNotFound(PathBuf),
#[error("Failed to serialize JSON: {0}")]
Json(#[from] serde_json::Error),
#[error("Unknown build system '{0}' for dependency '{1}'")]
UnknownBuildSystem(String, String),
#[error("Could not detect build system for '{0}' — specify build_system in smidr.toml")]
BuildSystemDetectionFailed(String),
#[error("Dependency '{name}' failed: {reason}")]
Dependency { name: String, reason: String },
#[error("Project already exists: {0}")]
ProjectAlreadyExists(PathBuf),
#[error("Invalid project name: {0}")]
InvalidProjectName(String),
}
pub type Result<T> = std::result::Result<T, BuildError>;