1#[derive(Debug)]
6pub enum ProjectError {
7 NoManifest,
8 InvalidManifest(String),
9 Multiple(Vec<Self>),
10 HclError(hcl::error::Error),
11 Other(String),
12}
13
14impl From<hcl::error::Error> for ProjectError {
15 fn from(e: hcl::error::Error) -> Self {
16 Self::HclError(e)
17 }
18}
19
20impl std::fmt::Display for ProjectError {
21 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22 match self {
23 Self::NoManifest => write!(f, "No manifest found"),
24 Self::InvalidManifest(e) => write!(f, "Invalid manifest: {e}"),
25 Self::Other(msg) => write!(f, "{msg}"),
26 Self::HclError(e) => write!(
27 f,
28 "Error parsing HCL: {e}{}",
29 e.location().map(|l| format!(" at {}:{}", l.line, l.col)).unwrap_or_default()
30 ),
31 Self::Multiple(errors) => {
32 write!(f, "Multiple errors:")?;
33 for error in errors {
34 write!(f, "\n - {error}")?;
35 }
36 Ok(())
37 }
38 }
39 }
40}
41
42impl std::error::Error for ProjectError {}