Skip to main content

cvkg_render_native/
error.rs

1//! Error types for the native rendering backend.
2//!
3//! Covers failures in window creation, GPU initialization, VDom diffing,
4//! window lifecycle, and event loop operations.
5
6use std::fmt;
7
8/// Errors that can occur in the native rendering backend.
9#[derive(Debug)]
10pub enum NativeError {
11    /// Window creation failed (e.g., display server unavailable).
12    WindowCreation(String),
13    /// GPU initialization failed (e.g., driver issues).
14    GpuInit(String),
15    /// VDom diff produced no patches but a rebuild was expected. This is a bug.
16    DiffEmpty,
17    /// A window was destroyed but events are still being dispatched.
18    WindowDestroyed(winit::window::WindowId),
19    /// An error occurred in the event loop.
20    EventLoop(String),
21}
22
23impl fmt::Display for NativeError {
24    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25        match self {
26            NativeError::WindowCreation(msg) => write!(
27                f,
28                "Window creation failed: {msg}. Check display server connection."
29            ),
30            NativeError::GpuInit(msg) => write!(
31                f,
32                "GPU initialization failed: {msg}. Verify drivers and GPU availability."
33            ),
34            NativeError::DiffEmpty => write!(
35                f,
36                "VDom diff produced no patches but rebuild was expected. This is a bug."
37            ),
38            NativeError::WindowDestroyed(id) => write!(
39                f,
40                "Window {id:?} was destroyed but events are still being dispatched."
41            ),
42            NativeError::EventLoop(msg) => write!(f, "Event loop error: {msg}"),
43        }
44    }
45}
46
47impl std::error::Error for NativeError {}