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
pub mod file_scan;
pub mod github;
pub mod markdown;
pub mod md_parser;
pub mod render;

use thiserror::Error as ThisError;

pub(crate) type Result<T> = std::result::Result<T, Error>;

// Map of values that can be passed to Renderer
pub type TomlMap = toml::value::Map<String, toml::value::Value>;

/// Errors generated by this library
#[derive(ThisError, Debug)]
pub enum Error {
    #[error("Parse error reading frontmatter {0}")]
    FrontmatterParse(String),

    #[error("Error reading handlebars template: {0}")]
    HandlebarsTemplate(#[from] handlebars::TemplateError),

    #[error("Error processing handlebars template: {0}")]
    HandlebarsRender(#[from] handlebars::RenderError),

    #[error("Invalid scan dir :{0}")]
    InvalidScanDir(String),

    #[error("Scan sources parameter cannot be empty")]
    ScanNoSources,

    #[error("Programmer error")]
    Bug(String),

    #[error("Policy '{0}', (id:{1}) is missing a 'slug' field. Update the field in Zenkit and try again")]
    MissingSlug(String, u64),

    #[error("Toml serialization {0}")]
    TomlSer(#[from] toml::ser::Error),

    #[error("Toml deserialization {0}")]
    TomlDeSer(#[from] toml::de::Error),

    #[error("IO Error")]
    Io(#[from] std::io::Error),

    #[error("Github api error for url {0}: {1}")]
    Github(String, String),

    #[error("Decoding Github content (url {0} with base64 :{1}")]
    Base64(String, String),

    #[error("Filenames may not contain non-uncode characters. '{0}' is invalid")]
    NonUnicodeFilename(String),

    #[error("File scan error {0}: To avoid this error, add this file to a .ignore file")]
    FileScan(String),

    #[error("File parse error {0}: To avoid this error, add this file to a .ignore file")]
    FileParse(String),
}