Skip to main content

sql_composer/
error.rs

1//! Error types for sql-composer.
2
3use std::path::PathBuf;
4
5/// The error type for sql-composer operations.
6#[derive(Debug, thiserror::Error)]
7pub enum Error {
8    /// A referenced template file was not found on any search path.
9    #[error("template not found: {path}")]
10    TemplateNotFound {
11        /// The path that was searched for.
12        path: PathBuf,
13    },
14
15    /// A parse error occurred while processing a template.
16    #[error("parse error at {location}: {message}")]
17    Parse {
18        /// Human-readable location description (e.g. line:col or offset).
19        location: String,
20        /// Description of the parse failure.
21        message: String,
22    },
23
24    /// A binding referenced in the template was not provided values.
25    #[error("binding '{name}' has no values")]
26    MissingBinding {
27        /// The name of the missing binding.
28        name: String,
29    },
30
31    /// A compose reference could not be resolved.
32    #[error("compose reference not found: {path}")]
33    ComposeNotFound {
34        /// The path of the unresolved compose reference.
35        path: PathBuf,
36    },
37
38    /// A command references sources that could not be resolved.
39    #[error("command source not found: {path}")]
40    CommandSourceNotFound {
41        /// The path of the unresolved source.
42        path: PathBuf,
43    },
44
45    /// An I/O error occurred while reading a template file.
46    #[error("io error: {0}")]
47    Io(#[from] std::io::Error),
48
49    /// A mock table was referenced but not registered.
50    #[error("mock table '{name}' not registered")]
51    MockNotFound {
52        /// The name of the missing mock table.
53        name: String,
54    },
55
56    /// A circular compose reference was detected.
57    #[error("circular compose reference detected: {path}")]
58    CircularReference {
59        /// The path where the cycle was detected.
60        path: PathBuf,
61    },
62
63    /// A slot referenced in a template was not provided by the caller.
64    #[error("missing slot '@{name}' — not provided by caller")]
65    MissingSlot {
66        /// The name of the missing slot.
67        name: String,
68    },
69}
70
71/// A specialized `Result` type for sql-composer operations.
72pub type Result<T> = std::result::Result<T, Error>;