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

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

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

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

    #[error(transparent)]
    Page(#[from] crate::page::PageError),

    #[error(transparent)]
    Directive(#[from] crate::directive::DirectiveError),

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

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

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

    #[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(transparent)]
    HtmlError(#[from] HtmlError),
}

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