mdvault_core/scripting/
hooks.rs

1//! Hook types and errors.
2//!
3//! This module provides types for hook execution, including the note context
4//! passed to hooks and error types for hook failures.
5
6use std::path::PathBuf;
7
8use thiserror::Error;
9
10/// Note context passed to Lua hooks.
11///
12/// Contains all information about a note that hooks might need to access.
13#[derive(Debug, Clone)]
14pub struct NoteContext {
15    /// Path to the note file (relative to vault root).
16    pub path: PathBuf,
17    /// Note type from frontmatter (e.g., "task", "meeting").
18    pub note_type: String,
19    /// Parsed frontmatter as YAML value.
20    pub frontmatter: serde_yaml::Value,
21    /// Full content of the note (including frontmatter).
22    pub content: String,
23}
24
25impl NoteContext {
26    /// Create a new NoteContext.
27    pub fn new(
28        path: PathBuf,
29        note_type: String,
30        frontmatter: serde_yaml::Value,
31        content: String,
32    ) -> Self {
33        Self { path, note_type, frontmatter, content }
34    }
35}
36
37/// Errors that can occur during hook execution.
38#[derive(Debug, Error)]
39pub enum HookError {
40    /// Template not found.
41    #[error("template not found: {0}")]
42    TemplateNotFound(String),
43
44    /// Capture not found.
45    #[error("capture not found: {0}")]
46    CaptureNotFound(String),
47
48    /// Macro not found.
49    #[error("macro not found: {0}")]
50    MacroNotFound(String),
51
52    /// Hook execution failed.
53    #[error("hook execution failed: {0}")]
54    Execution(String),
55
56    /// Lua runtime error.
57    #[error("Lua error: {0}")]
58    LuaError(String),
59
60    /// Template rendering error.
61    #[error("template render error: {0}")]
62    TemplateRender(String),
63
64    /// Capture execution error.
65    #[error("capture execution error: {0}")]
66    CaptureExecution(String),
67
68    /// Macro execution error.
69    #[error("macro execution error: {0}")]
70    MacroExecution(String),
71
72    /// IO error during hook execution.
73    #[error("IO error: {0}")]
74    Io(#[from] std::io::Error),
75}