dinja_core/error.rs
1//! Error types for MDX processing
2//!
3//! This module defines domain-specific error types for MDX processing operations.
4//! All errors use `thiserror` for automatic `std::error::Error` implementation.
5//!
6//! ## Error Hierarchy
7//!
8//! - **Domain Errors**: Use `MdxError` for parsing, transformation, and rendering errors
9//! - **Service Boundary**: Convert `MdxError` to `anyhow::Error` at HTTP handler boundaries
10//!
11//! ## Error Types
12//!
13//! - `FrontmatterParse`: YAML frontmatter parsing failures
14//! - `MarkdownRender`: Markdown to HTML conversion failures
15//! - `TsxParse`: TSX/JSX syntax parsing errors
16//! - `TsxTransform`: TSX to JavaScript transformation errors
17//! - `SourceType`: Source type detection failures
18//! - Resource limit errors: `ContentTooLarge`, `BatchTooLarge`, `ComponentCodeTooLarge`, `EngineCodeTooLarge`
19
20use thiserror::Error;
21
22/// Custom error type for MDX processing
23#[derive(Error, Debug)]
24pub enum MdxError {
25 /// Failed to parse YAML frontmatter from MDX content
26 #[error("Failed to parse frontmatter: {0}")]
27 FrontmatterParse(String),
28
29 /// Failed to render markdown to HTML
30 #[error("Failed to render markdown: {0}")]
31 MarkdownRender(String),
32
33 /// Failed to parse TSX/JSX syntax
34 #[error("Failed to parse TSX: {0}")]
35 TsxParse(String),
36
37 /// Failed to transform TSX to JavaScript
38 #[error("Failed to transform TSX: {0}")]
39 TsxTransform(String),
40
41 /// Failed to determine source type from file path
42 #[error("Failed to determine source type: {0}")]
43 SourceType(String),
44
45 /// Content size exceeds maximum allowed limit
46 #[error("Content size exceeds maximum allowed: {0} bytes")]
47 ContentTooLarge(usize),
48
49 /// Batch size exceeds maximum allowed limit
50 #[error("Batch size exceeds maximum allowed: {0} files")]
51 BatchTooLarge(usize),
52
53 /// Component code size exceeds maximum allowed limit
54 #[error("Component code size exceeds maximum allowed: {0} bytes")]
55 ComponentCodeTooLarge(usize),
56
57 /// Engine code size exceeds maximum allowed limit
58 #[error("Engine code size exceeds maximum allowed: {0} bytes")]
59 EngineCodeTooLarge(usize),
60}