summaryrefslogtreecommitdiff
path: root/src/error.rs
blob: dc2679fdf1982f3158f8a57d1e358e782742e0e4 (plain)
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
use crate::html::HtmlError;
use std::path::PathBuf;

#[derive(Debug, thiserror::Error)]
pub enum SiteError {
    #[error(transparent)]
    WalkDir(#[from] crate::srcdir::SourceDirError),

    #[error(transparent)]
    Util(#[from] crate::util::UtilError),

    #[error(transparent)]
    Git(#[from] crate::git::GitError),

    #[error("could not read file: {0}")]
    FileRead(PathBuf, #[source] std::io::Error),

    #[error("could not write file: {0}")]
    FileWrite(PathBuf, #[source] std::io::Error),

    #[error("string formatting error: {0}")]
    Format(#[source] std::fmt::Error),

    #[error("could not convert input text from {0} to UTF-8")]
    Utf8(PathBuf, #[source] std::string::FromUtf8Error),

    #[error("failed to compute relative path for {0} against {1}")]
    Relative(PathBuf, PathBuf),

    #[error("failed to create {0}")]
    CreateFile(PathBuf, #[source] std::io::Error),

    #[error("unknown directive {0}")]
    UnknownDirective(String),

    #[error("directive {0} does not allow unnamed arguments")]
    UnknownArgsNotAllowed(String),

    #[error("directive {0} has more than one unnamed argument")]
    TooManyUnnamedArgs(String),

    #[error("directive {0} is missing required argument {1}")]
    DirectiveMissingArg(String, String),

    #[error("directive {0} has unknown argument {1}")]
    DirectiveUnknownArg(String, String),

    #[error("link to missing page {1} on {0}")]
    PageMissing(PathBuf, PathBuf),

    #[error("attempt to use definition lists in Markdown: line {0}, column {1}")]
    DefinitionList(usize, usize),

    #[error("faileed to invoked git with subcommand {0} in {1}")]
    GitInvoke(String, PathBuf, #[source] std::io::Error),

    #[error("git {0} in in {1}:\n{2}")]
    GitError(String, PathBuf, String),

    #[error("failed to parse date: {0:?}")]
    UnknownTimestamp(String),

    #[error("failed to process page {0}")]
    PageProblem(PathBuf, #[source] Box<Self>),

    #[error(transparent)]
    PageSpec(#[from] crate::pagespec::PageSpecError),

    #[error("failed to parse wikitext, line {0}, column {1}: {2:?}")]
    WikitextSyntax(usize, usize, Vec<crate::token::TokenKind>),

    #[error("directive isn't implemented yet: {0}")]
    UnimplementedDirective(String),

    #[error("toc directive arguments 'levels' could not be parsed as an integer: {0}")]
    LevelsParse(String, #[source] std::num::ParseIntError),

    #[error(transparent)]
    HtmlError(#[from] HtmlError),
}

impl SiteError {
    pub fn wikitext_syntax(line: usize, col: usize, tokens: &[crate::token::TokenKind]) -> Self {
        let tokens = tokens.to_vec();
        Self::WikitextSyntax(line, col, tokens)
    }
}