1use std::path::PathBuf;
2
3use thiserror::Error;
4
5pub type Result<T, E = Error> = std::result::Result<T, E>;
6
7#[derive(Debug, Error)]
8pub enum Error {
9 #[error("I/O error at {path}: {source}")]
10 Io {
11 path: PathBuf,
12 #[source]
13 source: std::io::Error,
14 },
15
16 #[error("walk error: {0}")]
17 Walk(#[from] ignore::Error),
18
19 #[error("invalid glob {pattern:?}: {source}")]
20 Glob {
21 pattern: String,
22 #[source]
23 source: globset::Error,
24 },
25
26 #[error("YAML parse error: {0}")]
27 Yaml(#[from] serde_yaml_ng::Error),
28
29 #[error("unknown rule kind {0:?}")]
30 UnknownRuleKind(String),
31
32 #[error("rule {rule_id:?}: {message}")]
33 RuleConfig { rule_id: String, message: String },
34
35 #[error("{0}")]
36 Other(String),
37}
38
39impl Error {
40 pub fn rule_config(rule_id: impl Into<String>, message: impl Into<String>) -> Self {
41 Self::RuleConfig {
42 rule_id: rule_id.into(),
43 message: message.into(),
44 }
45 }
46}