Skip to main content

viewport_lib/
error.rs

1//! Error types for the viewport library.
2
3/// Errors that can occur during mesh upload and manipulation.
4#[derive(Debug, thiserror::Error)]
5#[non_exhaustive]
6pub enum ViewportError {
7    /// Mesh data has empty positions or indices.
8    #[error("empty mesh: {positions} positions, {indices} indices")]
9    EmptyMesh {
10        /// Number of positions provided.
11        positions: usize,
12        /// Number of indices provided.
13        indices: usize,
14    },
15
16    /// Positions and normals arrays have different lengths.
17    #[error("mesh length mismatch: {positions} positions vs {normals} normals")]
18    MeshLengthMismatch {
19        /// Number of positions provided.
20        positions: usize,
21        /// Number of normals provided.
22        normals: usize,
23    },
24
25    /// Mesh index is out of bounds for the mesh storage.
26    #[error("mesh index {index} out of bounds (mesh count: {count})")]
27    MeshIndexOutOfBounds {
28        /// The requested mesh index.
29        index: usize,
30        /// The number of meshes currently stored.
31        count: usize,
32    },
33
34    /// An index buffer entry references a vertex that does not exist.
35    #[error("invalid vertex index {vertex_index} (vertex count: {vertex_count})")]
36    InvalidVertexIndex {
37        /// The offending index value.
38        vertex_index: u32,
39        /// Total number of vertices.
40        vertex_count: usize,
41    },
42
43    /// Texture RGBA data has an unexpected size.
44    #[error("invalid texture data: expected {expected} bytes, got {actual}")]
45    InvalidTextureData {
46        /// Expected byte count (width * height * 4).
47        expected: usize,
48        /// Actual byte count provided.
49        actual: usize,
50    },
51
52    /// Attempted to access or replace a mesh slot that is empty (previously removed).
53    #[error("mesh slot {index} is empty")]
54    MeshSlotEmpty {
55        /// The slot index that was accessed.
56        index: usize,
57    },
58
59    /// Named scalar attribute not found on the given mesh.
60    #[error("attribute '{name}' not found on mesh {mesh_id}")]
61    AttributeNotFound {
62        /// The mesh index that was accessed.
63        mesh_id: usize,
64        /// The attribute name that was requested.
65        name: String,
66    },
67
68    /// Attribute data length does not match the existing buffer.
69    ///
70    /// `replace_attribute` requires the same vertex count as the original upload.
71    #[error("attribute length mismatch: expected {expected} f32 elements, got {got}")]
72    AttributeLengthMismatch {
73        /// Expected number of f32 elements (original attribute length).
74        expected: usize,
75        /// Actual number of f32 elements provided.
76        got: usize,
77    },
78}
79
80/// Convenience alias for `Result<T, ViewportError>`.
81pub type ViewportResult<T> = Result<T, ViewportError>;