Skip to main content

spatialrust_io/
error.rs

1use thiserror::Error;
2
3use spatialrust_core::SpatialError;
4
5/// IO-specific error type for SpatialRust.
6#[derive(Debug, Error, PartialEq)]
7pub enum IoError {
8    /// Underlying IO failure.
9    #[error("io failure: {0}")]
10    Io(String),
11
12    /// PCD header or payload parsing failed.
13    #[error("pcd parse error: {0}")]
14    PcdParse(String),
15
16    /// Unsupported or invalid PCD encoding.
17    #[error("pcd format error: {0}")]
18    PcdFormat(String),
19
20    /// PLY header or payload parsing failed.
21    #[error("ply parse error: {0}")]
22    PlyParse(String),
23
24    /// Unsupported or invalid PLY encoding.
25    #[error("ply format error: {0}")]
26    PlyFormat(String),
27
28    /// LAS header or payload parsing failed.
29    #[error("las parse error: {0}")]
30    LasParse(String),
31
32    /// Unsupported or invalid LAS encoding.
33    #[error("las format error: {0}")]
34    LasFormat(String),
35
36    /// LAZ compression support is not enabled.
37    #[error("laz format error: {0}")]
38    LazFormat(String),
39
40    /// E57 header or payload parsing failed.
41    #[error("e57 parse error: {0}")]
42    E57Parse(String),
43
44    /// Unsupported or invalid E57 encoding.
45    #[error("e57 format error: {0}")]
46    E57Format(String),
47
48    /// COPC header or payload parsing failed.
49    #[error("copc parse error: {0}")]
50    CopcParse(String),
51
52    /// Unsupported or invalid COPC encoding.
53    #[error("copc format error: {0}")]
54    CopcFormat(String),
55
56    /// Bounded streaming contract failure.
57    #[error("streaming io error: {0}")]
58    Streaming(String),
59
60    /// Input/output root or dataset path contract failure.
61    #[error("storage path error: {0}")]
62    Storage(String),
63
64    /// Dataset manifest serialization or receipt failure.
65    #[error("manifest error: {0}")]
66    Manifest(String),
67
68    /// Core data model error propagated from `spatialrust-core`.
69    #[error(transparent)]
70    Core(#[from] SpatialError),
71}
72
73#[cfg(feature = "streaming")]
74impl From<spatialrust_records::RecordsError> for IoError {
75    fn from(error: spatialrust_records::RecordsError) -> Self {
76        Self::Streaming(error.to_string())
77    }
78}
79
80impl From<std::io::Error> for IoError {
81    fn from(error: std::io::Error) -> Self {
82        Self::Io(error.to_string())
83    }
84}
85
86#[cfg_attr(not(feature = "io-pcd"), allow(dead_code))]
87pub(crate) fn pcd_parse(message: impl Into<String>) -> IoError {
88    IoError::PcdParse(message.into())
89}
90
91#[cfg_attr(not(feature = "io-pcd"), allow(dead_code))]
92pub(crate) fn pcd_format(message: impl Into<String>) -> IoError {
93    IoError::PcdFormat(message.into())
94}
95
96#[cfg_attr(not(feature = "io-ply"), allow(dead_code))]
97pub(crate) fn ply_parse(message: impl Into<String>) -> IoError {
98    IoError::PlyParse(message.into())
99}
100
101#[cfg_attr(not(feature = "io-ply"), allow(dead_code))]
102pub(crate) fn ply_format(message: impl Into<String>) -> IoError {
103    IoError::PlyFormat(message.into())
104}
105
106#[cfg_attr(not(feature = "io-las"), allow(dead_code))]
107pub(crate) fn las_parse(message: impl Into<String>) -> IoError {
108    IoError::LasParse(message.into())
109}
110
111#[cfg_attr(not(feature = "io-las"), allow(dead_code))]
112pub(crate) fn las_format(message: impl Into<String>) -> IoError {
113    IoError::LasFormat(message.into())
114}
115
116#[allow(dead_code)]
117pub(crate) fn laz_format(message: impl Into<String>) -> IoError {
118    IoError::LazFormat(message.into())
119}
120
121#[cfg_attr(not(feature = "io-e57"), allow(dead_code))]
122pub(crate) fn e57_parse(message: impl Into<String>) -> IoError {
123    IoError::E57Parse(message.into())
124}
125
126#[cfg_attr(not(feature = "io-e57"), allow(dead_code))]
127pub(crate) fn e57_format(message: impl Into<String>) -> IoError {
128    IoError::E57Format(message.into())
129}
130
131#[cfg_attr(not(feature = "io-copc"), allow(dead_code))]
132pub(crate) fn copc_parse(message: impl Into<String>) -> IoError {
133    IoError::CopcParse(message.into())
134}
135
136#[cfg_attr(not(feature = "io-copc"), allow(dead_code))]
137pub(crate) fn copc_format(message: impl Into<String>) -> IoError {
138    IoError::CopcFormat(message.into())
139}