Skip to main content

polyscope_core/
error.rs

1//! Error types for polyscope-rs.
2
3use thiserror::Error;
4
5/// The main error type for polyscope-rs operations.
6#[derive(Error, Debug)]
7pub enum PolyscopeError {
8    /// Polyscope has not been initialized.
9    #[error("polyscope not initialized - call polyscope_rs::init() first")]
10    NotInitialized,
11
12    /// Polyscope has already been initialized.
13    #[error("polyscope already initialized")]
14    AlreadyInitialized,
15
16    /// A structure with the given name already exists.
17    #[error("structure '{0}' already exists")]
18    StructureExists(String),
19
20    /// A structure with the given name was not found.
21    #[error("structure '{0}' not found")]
22    StructureNotFound(String),
23
24    /// A quantity with the given name already exists.
25    #[error("quantity '{0}' already exists on structure '{1}'")]
26    QuantityExists(String, String),
27
28    /// A quantity with the given name was not found.
29    #[error("quantity '{0}' not found on structure '{1}'")]
30    QuantityNotFound(String, String),
31
32    /// A material with the given name already exists.
33    #[error("material '{0}' already exists")]
34    MaterialExists(String),
35
36    /// Failed to load a material image.
37    #[error("material load error: {0}")]
38    MaterialLoadError(String),
39
40    /// Data size mismatch.
41    #[error("data size mismatch: expected {expected}, got {actual}")]
42    SizeMismatch { expected: usize, actual: usize },
43
44    /// Rendering error.
45    #[error("render error: {0}")]
46    RenderError(String),
47
48    /// I/O error.
49    #[error("I/O error: {0}")]
50    IoError(#[from] std::io::Error),
51
52    /// JSON serialization error.
53    #[error("JSON error: {0}")]
54    JsonError(#[from] serde_json::Error),
55}
56
57/// A specialized Result type for polyscope-rs operations.
58pub type Result<T> = std::result::Result<T, PolyscopeError>;