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
55impl ValidatorError {
56 #[must_use]
60 pub fn code(&self) -> &'static str {
61 match self {
62 Self::Config { .. } => "E001",
63 Self::ContainerStartup { .. } => "E002",
64 Self::ContainerExec { .. } => "E003",
65 Self::SetupFailed { .. } => "E004",
66 Self::QueryFailed { .. } => "E005",
67 Self::ValidationFailed { .. } => "E006",
68 Self::UnknownValidator { .. } => "E007",
69 Self::InvalidConfig { .. } => "E008",
70 Self::FixturesError { .. } => "E009",
71 Self::ScriptNotFound { .. } => "E010",
72 }
73 }
74}