Skip to main content

goud_engine/core/error/
context.rs

1//! Error context propagation for GoudEngine.
2//!
3//! Provides subsystem and operation metadata that can be attached to errors
4//! stored in thread-local storage, queryable across FFI.
5
6/// Metadata describing where an error originated.
7///
8/// Stores the subsystem (e.g., graphics, ECS) and specific operation
9/// (e.g., "shader_compile", "entity_spawn") that produced an error.
10/// Designed for FFI consumption alongside `GoudError`.
11#[derive(Clone, Debug, Default)]
12pub struct GoudErrorContext {
13    /// The engine subsystem that produced the error (e.g., "graphics").
14    pub subsystem: &'static str,
15    /// The specific operation that failed (e.g., "shader_compile").
16    pub operation: &'static str,
17}
18
19impl GoudErrorContext {
20    /// Creates a new error context with the given subsystem and operation.
21    ///
22    /// # Example
23    ///
24    /// ```
25    /// use goud_engine::core::error::GoudErrorContext;
26    /// use goud_engine::core::error::context::subsystems;
27    ///
28    /// let ctx = GoudErrorContext::new(subsystems::GRAPHICS, "shader_compile");
29    /// assert_eq!(ctx.subsystem, "graphics");
30    /// assert_eq!(ctx.operation, "shader_compile");
31    /// ```
32    pub fn new(subsystem: &'static str, operation: &'static str) -> Self {
33        Self {
34            subsystem,
35            operation,
36        }
37    }
38}
39
40/// Well-known subsystem constants for error context.
41pub mod subsystems {
42    /// Graphics/rendering subsystem.
43    pub const GRAPHICS: &str = "graphics";
44    /// Entity Component System subsystem.
45    pub const ECS: &str = "ecs";
46    /// Audio subsystem.
47    pub const AUDIO: &str = "audio";
48    /// Platform/windowing subsystem.
49    pub const PLATFORM: &str = "platform";
50    /// Resource/asset management subsystem.
51    pub const RESOURCE: &str = "resource";
52    /// Provider subsystem.
53    pub const PROVIDER: &str = "provider";
54    /// Input handling subsystem.
55    pub const INPUT: &str = "input";
56    /// Internal/unexpected errors.
57    pub const INTERNAL: &str = "internal";
58}