mdbook_validator/
error.rs1use thiserror::Error;
7
8#[derive(Debug, Error)]
13pub enum ValidatorError {
14 #[error("[E001] Configuration error: {message}")]
16 Config { message: String },
17
18 #[error("[E002] Container startup failed: {message}")]
20 ContainerStartup { message: String },
21
22 #[error("[E003] Container exec failed: {message}")]
24 ContainerExec { message: String },
25
26 #[error("[E004] Setup script failed (exit {exit_code}): {message}")]
28 SetupFailed { exit_code: i32, message: String },
29
30 #[error("[E005] Query execution failed (exit {exit_code}): {message}")]
32 QueryFailed { exit_code: i32, message: String },
33
34 #[error("[E006] Validation failed (exit {exit_code}): {message}")]
36 ValidationFailed { exit_code: i32, message: String },
37
38 #[error("[E007] Unknown validator '{name}'")]
40 UnknownValidator { name: String },
41
42 #[error("[E008] Invalid validator config for '{name}': {reason}")]
44 InvalidConfig { name: String, reason: String },
45
46 #[error("[E009] Fixtures directory error: {message}")]
48 FixturesError { message: String },
49
50 #[error("[E010] Script not found: {path}")]
52 ScriptNotFound { path: String },
53
54 #[error("[E011] 'hidden' and 'skip' are mutually exclusive")]
56 MutuallyExclusiveAttributes,
57}
58
59impl ValidatorError {
60 #[must_use]
64 pub fn code(&self) -> &'static str {
65 match self {
66 Self::Config { .. } => "E001",
67 Self::ContainerStartup { .. } => "E002",
68 Self::ContainerExec { .. } => "E003",
69 Self::SetupFailed { .. } => "E004",
70 Self::QueryFailed { .. } => "E005",
71 Self::ValidationFailed { .. } => "E006",
72 Self::UnknownValidator { .. } => "E007",
73 Self::InvalidConfig { .. } => "E008",
74 Self::FixturesError { .. } => "E009",
75 Self::ScriptNotFound { .. } => "E010",
76 Self::MutuallyExclusiveAttributes => "E011",
77 }
78 }
79}