Skip to main content

npmgen_core/
error.rs

1//! Crate-facade error wrapping each phase's typed error and the pipeline's own
2//! preconditions, with the source chain preserved. The per-phase errors are
3//! boxed so the facade (and the `Result` it travels in) stays small.
4
5/// Any failure of the generation pipeline.
6#[derive(Debug, thiserror::Error)]
7pub enum Error {
8    #[error(transparent)]
9    Project(Box<crate::project::ProjectError>),
10
11    #[error(transparent)]
12    Target(Box<crate::target::TargetError>),
13
14    #[error(transparent)]
15    Compile(Box<crate::compile::CompileError>),
16
17    #[error(transparent)]
18    Npm(Box<crate::npm::NpmError>),
19
20    #[error("git tag {tag} does not match the package version {expected}")]
21    TagMismatch { tag: String, expected: String },
22}
23
24impl From<crate::project::ProjectError> for Error {
25    fn from(error: crate::project::ProjectError) -> Self {
26        Self::Project(Box::new(error))
27    }
28}
29
30impl From<crate::target::TargetError> for Error {
31    fn from(error: crate::target::TargetError) -> Self {
32        Self::Target(Box::new(error))
33    }
34}
35
36impl From<crate::compile::CompileError> for Error {
37    fn from(error: crate::compile::CompileError) -> Self {
38        Self::Compile(Box::new(error))
39    }
40}
41
42impl From<crate::npm::NpmError> for Error {
43    fn from(error: crate::npm::NpmError) -> Self {
44        Self::Npm(Box::new(error))
45    }
46}
47
48pub type Result<T> = std::result::Result<T, Error>;