context_weaver/
errors.rs

1// src/errors.rs
2use thiserror::Error;
3
4#[derive(Debug, Error)]
5pub enum WorldInfoError {
6    #[error("Parser error: {0}")]
7    ParserError(ParserError),
8    #[error("Processor error: {0}")]
9    ProcessorError(String),
10    #[error("Evaluation error: {0}")]
11    EvaluationError(String),
12}
13
14/// Errors that can occur during parsing and processing of world info text.
15#[derive(Error, Debug)]
16pub enum ParserError {
17    /// Error originating from the pest parser (e.g., syntax error).
18    #[error("Parsing error: {0}")]
19    PestParse(#[from] pest::error::Error<Rule>),
20
21    /// Error during JSON serialization or deserialization of properties.
22    #[error("JSON processing error: {0}")]
23    Json(#[from] serde_json::Error),
24
25    /// Failed to find or instantiate a processor.
26    #[error("Processor '{0}' not found or failed to instantiate: {1}")]
27    ProcessorInstantiation(String, String), // name, underlying error string
28
29    /// An invalid rule was encountered during AST construction.
30    #[error("Invalid parsing rule encountered: {0:?}")]
31    InvalidRule(Rule),
32
33    /// Error originating from a processor's execution.
34    // Assuming WorldInfoError can be converted or displayed
35    #[error("Processor execution failed: {0}")]
36    ProcessorExecution(String), // Displayable error from WorldInfoError
37
38    /// Trigger tag is missing the required 'id' attribute.
39    #[error("Trigger tag missing 'id' attribute: {0}")]
40    MissingTriggerId(String),
41
42    /// Generic processing error.
43    #[error("Processing error: {0}")]
44    Processing(String),
45}
46
47// Import the Rule enum generated by pest
48use crate::parser::Rule;