Flint Engine / Guide / API Reference

flint_core/
error.rs

1//! Error types for Flint
2
3use thiserror::Error;
4
5/// The main error type for Flint operations
6#[derive(Debug, Error)]
7pub enum FlintError {
8    #[error("Entity not found: {0}")]
9    EntityNotFound(String),
10
11    #[error("Component not found: {0}")]
12    ComponentNotFound(String),
13
14    #[error("Archetype not found: {0}")]
15    ArchetypeNotFound(String),
16
17    #[error("Schema not found: {0}")]
18    SchemaNotFound(String),
19
20    #[error("Validation error: {0}")]
21    ValidationError(String),
22
23    #[error("Parse error: {0}")]
24    ParseError(String),
25
26    #[error("IO error: {0}")]
27    IoError(#[from] std::io::Error),
28
29    #[error("TOML parse error: {0}")]
30    TomlParseError(String),
31
32    #[error("TOML serialization error: {0}")]
33    TomlSerError(String),
34
35    #[error("Scene error: {0}")]
36    SceneError(String),
37
38    #[error("Query error: {0}")]
39    QueryError(String),
40
41    #[error("Render error: {0}")]
42    RenderError(String),
43
44    #[error("Duplicate entity name: {0}")]
45    DuplicateEntityName(String),
46
47    #[error("Invalid field type: expected {expected}, got {got}")]
48    InvalidFieldType { expected: String, got: String },
49
50    #[error("Missing required field: {0}")]
51    MissingRequiredField(String),
52
53    #[error("Value out of range: {field} must be between {min} and {max}, got {value}")]
54    ValueOutOfRange {
55        field: String,
56        min: f64,
57        max: f64,
58        value: f64,
59    },
60
61    #[error("Invalid enum value: {value} is not one of {allowed:?}")]
62    InvalidEnumValue { value: String, allowed: Vec<String> },
63
64    #[error("Constraint violation: {0}")]
65    ConstraintViolation(String),
66
67    #[error("Constraint load error: {0}")]
68    ConstraintLoadError(String),
69
70    #[error("Asset error: {0}")]
71    AssetError(String),
72
73    #[error("Import error: {0}")]
74    ImportError(String),
75
76    #[error("Fix cycle detected: {0}")]
77    FixCycleDetected(String),
78
79    #[error("Physics error: {0}")]
80    PhysicsError(String),
81
82    #[error("Audio error: {0}")]
83    AudioError(String),
84
85    #[error("Runtime error: {0}")]
86    RuntimeError(String),
87
88    #[error("Animation error: {0}")]
89    AnimationError(String),
90
91    #[error("Generation error: {0}")]
92    GenerationError(String),
93}
94
95/// Result type alias for Flint operations
96pub type Result<T> = std::result::Result<T, FlintError>;
97
98impl From<toml::de::Error> for FlintError {
99    fn from(err: toml::de::Error) -> Self {
100        FlintError::TomlParseError(err.to_string())
101    }
102}
103
104impl From<toml::ser::Error> for FlintError {
105    fn from(err: toml::ser::Error) -> Self {
106        FlintError::TomlSerError(err.to_string())
107    }
108}