ricecoder_storage/markdown_config/
error.rs1use std::path::PathBuf;
4use thiserror::Error;
5
6#[derive(Debug, Error)]
8pub enum MarkdownConfigError {
9 #[error("Failed to parse markdown: {message}")]
11 ParseError { message: String },
12
13 #[error("Invalid YAML frontmatter: {message}")]
15 YamlError { message: String },
16
17 #[error("Schema validation failed: {message}")]
19 ValidationError { message: String },
20
21 #[error("Failed to load configuration from {path}: {message}")]
23 LoadError { path: PathBuf, message: String },
24
25 #[error("Registration failed: {message}")]
27 RegistrationError { message: String },
28
29 #[error("File watch error: {message}")]
31 WatchError { message: String },
32
33 #[error("Missing required field: {field}")]
35 MissingField { field: String },
36
37 #[error("Invalid value for field '{field}': {message}")]
39 InvalidFieldValue { field: String, message: String },
40
41 #[error("IO error: {0}")]
43 IoError(#[from] std::io::Error),
44}
45
46impl MarkdownConfigError {
47 pub fn parse_error(message: impl Into<String>) -> Self {
49 Self::ParseError {
50 message: message.into(),
51 }
52 }
53
54 pub fn yaml_error(message: impl Into<String>) -> Self {
56 Self::YamlError {
57 message: message.into(),
58 }
59 }
60
61 pub fn validation_error(message: impl Into<String>) -> Self {
63 Self::ValidationError {
64 message: message.into(),
65 }
66 }
67
68 pub fn load_error(path: impl Into<PathBuf>, message: impl Into<String>) -> Self {
70 Self::LoadError {
71 path: path.into(),
72 message: message.into(),
73 }
74 }
75
76 pub fn registration_error(message: impl Into<String>) -> Self {
78 Self::RegistrationError {
79 message: message.into(),
80 }
81 }
82
83 pub fn missing_field(field: impl Into<String>) -> Self {
85 Self::MissingField {
86 field: field.into(),
87 }
88 }
89
90 pub fn invalid_field_value(field: impl Into<String>, message: impl Into<String>) -> Self {
92 Self::InvalidFieldValue {
93 field: field.into(),
94 message: message.into(),
95 }
96 }
97
98 pub fn watch_error(message: impl Into<String>) -> Self {
100 Self::WatchError {
101 message: message.into(),
102 }
103 }
104}
105
106pub type MarkdownConfigResult<T> = Result<T, MarkdownConfigError>;