Skip to main content

shape_ast/error/
mod.rs

1//! Unified error handling for Shape
2//!
3//! This module provides a comprehensive error type that covers all error cases
4//! in the Shape language, from parsing to execution.
5
6#[macro_use]
7pub mod macros;
8pub mod parse_error;
9pub mod pest_converter;
10pub mod renderer;
11
12// New submodules for splitting error handling
13pub mod context;
14pub mod conversions;
15pub mod formatting;
16pub mod impls;
17pub mod suggestions;
18pub mod types;
19
20// Re-export parse_error types
21pub use parse_error::{
22    ErrorSeverity, ExpectedToken, Highlight, HighlightStyle, IdentifierContext,
23    MissingComponentKind, NumberError, ParseErrorKind, RelatedInfo, SourceContext, SourceLine,
24    StringDelimiter, StructuredParseError, Suggestion, SuggestionConfidence, TextEdit,
25    TokenCategory, TokenInfo, TokenKind,
26};
27
28// Re-export renderer types
29pub use renderer::{CliErrorRenderer, CliRendererConfig, ErrorRenderer};
30
31// Re-export core types from types module
32pub use types::{ErrorCode, ErrorNote, ShapeError, SourceLocation};
33
34// Re-export context utilities
35pub use context::{ErrorContext, Result, ResultExt, span_to_location};
36
37/// Helper macros for creating errors with location
38#[macro_export]
39macro_rules! parse_error {
40    ($msg:expr) => {
41        $crate::error::ShapeError::ParseError {
42            message: $msg.to_string(),
43            location: None,
44        }
45    };
46    ($msg:expr, $loc:expr) => {
47        $crate::error::ShapeError::ParseError {
48            message: $msg.to_string(),
49            location: Some($loc),
50        }
51    };
52}
53
54#[macro_export]
55macro_rules! runtime_error {
56    ($msg:expr) => {
57        $crate::error::ShapeError::RuntimeError {
58            message: $msg.to_string(),
59            location: None,
60        }
61    };
62    ($msg:expr, $loc:expr) => {
63        $crate::error::ShapeError::RuntimeError {
64            message: $msg.to_string(),
65            location: Some($loc),
66        }
67    };
68}
69
70#[macro_export]
71macro_rules! semantic_error {
72    ($msg:expr) => {
73        $crate::error::ShapeError::SemanticError {
74            message: $msg.to_string(),
75            location: None,
76        }
77    };
78    ($msg:expr, $loc:expr) => {
79        $crate::error::ShapeError::SemanticError {
80            message: $msg.to_string(),
81            location: Some($loc),
82        }
83    };
84}