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    #[error("Processing error: {0}")]
43    Processing(String),
44
45    #[error("Undefined variable: {0}")]
46    UndefinedVariable(String),
47
48    #[error("Variable already exists: {0}")]
49    VariableAlreadyExists(String),
50
51    #[error("Insufficient permissions: {0}")]
52    InsufficientPermissions(String),
53
54    #[error("Type error: {0}")]
55    TypeError(String),
56
57    #[error("Evaluation error: {0}")] // For variable/macro evaluation issues
58    Evaluation(String),
59    
60    #[error("Internal parser error: {0}")]
61    Internal(String),
62
63    #[error("Regex compilation error: {0}")]
64    RegexCompilation(String, String),
65}
66
67// Import the Rule enum generated by pest
68use crate::parser::Rule;