#![cfg_attr(coverage_nightly, coverage(off))]
use std::path::PathBuf;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum ScaffoldError {
#[error("Template not found: {0}")]
TemplateNotFound(String),
#[error("Invalid agent configuration: {0}")]
InvalidConfiguration(String),
#[error("Directory already exists: {}", .0.display())]
DirectoryExists(PathBuf),
#[error("Template generation failed")]
GenerationFailed(#[source] anyhow::Error),
#[error("Post-generation hook failed: {0}")]
HookFailed(String),
#[error("Template validation failed")]
ValidationFailed(#[source] anyhow::Error),
#[error("Incompatible template version: requires PMAT {required}, but running {current}")]
IncompatibleVersion {
required: String,
current: String,
},
#[error("Missing required feature: {0}")]
MissingFeature(String),
#[error("I/O error")]
IoError(#[from] std::io::Error),
#[error("Template rendering failed: {0}")]
RenderError(String),
#[error("Invalid template syntax: {0}")]
InvalidTemplate(String),
#[error("Operation cancelled by user")]
UserCancelled,
#[error("Network error: {0}")]
NetworkError(String),
#[error("Parse error: {0}")]
ParseError(String),
}
pub type ScaffoldResult<T> = Result<T, ScaffoldError>;
#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_error_display() {
let err = ScaffoldError::TemplateNotFound("my-template".to_string());
assert_eq!(err.to_string(), "Template not found: my-template");
let err = ScaffoldError::DirectoryExists(PathBuf::from("/tmp/test"));
assert_eq!(err.to_string(), "Directory already exists: /tmp/test");
let err = ScaffoldError::IncompatibleVersion {
required: "0.30.0".to_string(),
current: "0.29.0".to_string(),
};
assert_eq!(
err.to_string(),
"Incompatible template version: requires PMAT 0.30.0, but running 0.29.0"
);
}
#[test]
fn test_error_conversion() {
let err = ScaffoldError::UserCancelled;
let anyhow_err: anyhow::Error = err.into();
assert_eq!(anyhow_err.to_string(), "Operation cancelled by user");
}
#[test]
fn test_io_error_conversion() {
let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "file not found");
let scaffold_err = ScaffoldError::from(io_err);
assert!(matches!(scaffold_err, ScaffoldError::IoError(_)));
}
}
#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod property_tests {
use proptest::prelude::*;
proptest! {
#[test]
fn basic_property_stability(_input in ".*") {
prop_assert!(true);
}
#[test]
fn module_consistency_check(_x in 0u32..1000) {
prop_assert!(_x < 1001);
}
}
}