Skip to main content

llmwiki_tooling/
error.rs

1use std::path::PathBuf;
2
3use crate::page::PageId;
4
5#[derive(Debug, thiserror::Error)]
6pub enum ConfigError {
7    #[error("reading config '{path}'")]
8    Read {
9        path: PathBuf,
10        #[source]
11        source: std::io::Error,
12    },
13
14    #[error("parsing config '{path}'")]
15    Parse {
16        path: PathBuf,
17        #[source]
18        source: toml::de::Error,
19    },
20
21    #[error("unknown citation preset: '{0}'")]
22    UnknownPreset(String),
23
24    #[error("invalid citation pattern '{name}'")]
25    InvalidPattern {
26        name: String,
27        #[source]
28        source: regex_lite::Error,
29    },
30
31    #[error("invalid ignore pattern '{pattern}'")]
32    InvalidIgnorePattern {
33        pattern: String,
34        #[source]
35        source: ignore::Error,
36    },
37
38    #[error("compiling ignore patterns")]
39    CompileIgnorePatterns {
40        #[source]
41        source: ignore::Error,
42    },
43
44    #[error("config validation: {0}")]
45    Validation(String),
46}
47
48#[derive(Debug, thiserror::Error)]
49pub enum WikiError {
50    #[error("wiki root not found (searched ancestors of {start})")]
51    RootNotFound { start: PathBuf },
52
53    #[error("reading '{path}'")]
54    ReadFile {
55        path: PathBuf,
56        #[source]
57        source: std::io::Error,
58    },
59
60    #[error("writing '{path}'")]
61    WriteFile {
62        path: PathBuf,
63        #[source]
64        source: std::io::Error,
65    },
66
67    #[error("walking '{path}'")]
68    Walk {
69        path: PathBuf,
70        #[source]
71        source: ignore::Error,
72    },
73
74    #[error("invalid ignore pattern '{pattern}'")]
75    InvalidIgnorePattern {
76        pattern: String,
77        #[source]
78        source: ignore::Error,
79    },
80
81    #[error("compiling ignore patterns")]
82    CompileIgnorePatterns {
83        #[source]
84        source: ignore::Error,
85    },
86
87    #[error("parsing frontmatter in '{path}'")]
88    Frontmatter {
89        path: PathBuf,
90        #[source]
91        source: FrontmatterError,
92    },
93
94    #[error("page not found: {0}")]
95    PageNotFound(PageId),
96
97    #[error("duplicate page ID '{id}' in '{path1}' and '{path2}'")]
98    DuplicatePageId {
99        id: String,
100        path1: PathBuf,
101        path2: PathBuf,
102    },
103}
104
105#[derive(Debug, thiserror::Error)]
106pub enum FrontmatterError {
107    #[error("YAML parse error near '{context}'")]
108    Yaml {
109        #[source]
110        source: Box<serde_yml::Error>,
111        context: String,
112    },
113}
114
115#[derive(Debug, thiserror::Error)]
116pub enum RenameError {
117    #[error(transparent)]
118    Wiki(#[from] WikiError),
119
120    #[error("source page not found: {0}")]
121    SourceNotFound(PageId),
122
123    #[error("target page already exists: '{path}'")]
124    TargetExists { path: PathBuf },
125}
126
127#[derive(Debug, thiserror::Error)]
128pub enum LintError {
129    #[error(transparent)]
130    Wiki(#[from] WikiError),
131
132    #[error("{count} lint error(s) found")]
133    Failed { count: usize },
134}