obsidian_parser/
error.rs

1//! Error handling for Obsidian vault parsing operations
2
3use std::path::PathBuf;
4use thiserror::Error;
5
6/// Main error type for Obsidian parsing operations
7#[derive(Debug, Error)]
8pub enum Error {
9    /// I/O operation failed (file reading, directory traversal, etc.)
10    #[error("I/O error: {0}")]
11    Io(#[from] std::io::Error),
12
13    /// Invalid frontmatter format detected
14    ///
15    /// Occurs when:
16    /// - Frontmatter delimiters are incomplete (`---` missing)
17    /// - Content between delimiters is empty
18    ///
19    /// # Example
20    /// Parsing a file with malformed frontmatter:
21    /// ```text
22    /// ---
23    /// incomplete yaml
24    /// // Missing closing ---
25    /// ```
26    #[error("Invalid frontmatter format")]
27    InvalidFormat,
28
29    /// YAML parsing error in frontmatter properties
30    ///
31    /// # Example
32    /// Parsing invalid YAML syntax:
33    /// ```text
34    /// ---
35    /// key: @invalid_value
36    /// ---
37    /// ```
38    #[error("YAML parsing error: {0}")]
39    Yaml(#[from] serde_yml::Error),
40
41    /// Expected a directory path
42    ///
43    /// # Example
44    /// ```no_run
45    /// use obsidian_parser::prelude::*;
46    ///
47    /// // Will fail if passed a file path
48    /// Vault::open_default("notes.md").unwrap();
49    /// ```
50    #[error("Path: `{0}` is not a directory")]
51    IsNotDir(PathBuf),
52
53    /// Expected a file path
54    ///
55    /// # Example
56    /// ```no_run
57    /// use obsidian_parser::prelude::*;
58    ///
59    /// // Will fail if passed a directory path
60    /// ObFileOnDisk::from_file_default("/home/test");
61    /// ```
62    #[error("Path: `{0}` is not a directory")]
63    IsNotFile(PathBuf),
64}