1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
use crate::config::{AnswerConfigError, CatalogError};
use crate::system::SystemError;
use crate::util::SourceError;
use crate::ArchetypeError;
use std::path::PathBuf;

#[derive(Debug)]
pub enum ArchetectError {
    AnswerConfigError { source: String, cause: AnswerConfigError },
    ArchetypeError(ArchetypeError),
    GenericError(String),
    RenderError(RenderError),
    SystemError(SystemError),
    SourceError(SourceError),
    CatalogError(CatalogError),
    IoError(std::io::Error),
}

impl From<ArchetypeError> for ArchetectError {
    fn from(error: ArchetypeError) -> Self {
        ArchetectError::ArchetypeError(error)
    }
}

impl From<RenderError> for ArchetectError {
    fn from(error: RenderError) -> Self {
        ArchetectError::RenderError(error)
    }
}

impl From<String> for ArchetectError {
    fn from(error: String) -> Self {
        ArchetectError::GenericError(error)
    }
}

impl From<SystemError> for ArchetectError {
    fn from(error: SystemError) -> Self {
        ArchetectError::SystemError(error)
    }
}

impl From<SourceError> for ArchetectError {
    fn from(error: SourceError) -> Self {
        ArchetectError::SourceError(error)
    }
}

impl From<CatalogError> for ArchetectError {
    fn from(error: CatalogError) -> Self {
        ArchetectError::CatalogError(error)
    }
}

impl From<std::io::Error> for ArchetectError {
    fn from(error: std::io::Error) -> ArchetectError {
        ArchetectError::IoError(error)
    }
}

#[derive(Debug)]
pub enum RenderError {
    InvalidPathCharacters {
        source: PathBuf,
    },
    PathRenderError {
        source: PathBuf,
        error: crate::template_engine::Error,
        message: String,
    },
    FileRenderError {
        source: PathBuf,
        error: crate::template_engine::Error,
        message: String,
    },

    FileRenderIOError {
        source: PathBuf,
        error: std::io::Error,
        message: String,
    },
    StringRenderError {
        source: String,
        error: crate::template_engine::Error,
        message: String,
    },
    IOError {
        error: std::io::Error,
        message: String,
    },
}

impl From<std::io::Error> for RenderError {
    fn from(error: std::io::Error) -> Self {
        let message = error.to_string();
        RenderError::IOError { error, message }
    }
}