Skip to main content

hemplate_core/
error.rs

1//! Host-side errors for parsing and extracting hemplate templates.
2
3use thiserror::Error;
4
5/// Top-level error type for host-side template processing.
6#[derive(Debug, Error)]
7pub enum BuildError {
8    /// A parse error occurred.
9    #[error("parse error: {0}")]
10    Parse(#[from] ParseError),
11    /// An extraction error occurred.
12    #[error("extraction error: {0}")]
13    Extraction(#[from] ExtractionError),
14    /// An I/O error occurred.
15    #[error("io error: {0}")]
16    Io(#[from] std::io::Error),
17}
18
19/// An error that occurs during template parsing.
20#[derive(Debug, Error)]
21#[error("parse error at byte {byte_offset}: {message}")]
22pub struct ParseError {
23    /// The byte offset in the source where the error occurred.
24    pub byte_offset: usize,
25    /// A human-readable description of the error.
26    pub message: String,
27}
28
29/// An error that occurs during AST node extraction.
30#[derive(Debug, Error)]
31#[error("extraction error for node kind '{node_kind}': {message}")]
32pub struct ExtractionError {
33    /// The tree-sitter node kind where extraction failed.
34    pub node_kind: String,
35    /// A human-readable description of the error.
36    pub message: String,
37}