1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
//! The error type for scene construction and editing.
//!
//! Every variant carries a stable registry code so callers can match on the
//! condition across versions without parsing message text.
use thiserror::Error;
/// Everything that can go wrong building or editing a scene.
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum CoreError {
/// A disconnected-surface component policy is malformed.
#[error(transparent)]
SurfaceComponentPolicy(#[from] crate::SurfaceComponentPolicyError),
/// A spatial hierarchy exceeded the compact GPU index layout.
#[error(transparent)]
SpatialIndex(#[from] molgfx_math::BvhBuildError),
/// The source structure failed to parse.
#[error("structure could not be read: {summary}")]
StructureRead {
/// A one-line rendering of the parser's findings.
summary: String,
},
/// A selection referenced an annotation the structure does not carry.
#[error("selection references absent annotation {name:?}")]
AbsentAnnotation {
/// The annotation the selection asked for.
name: String,
},
/// A caller-supplied scalar grid violates the portable volume contract.
#[error("invalid density volume: {reason}")]
InvalidVolume {
/// Stable human-readable validation reason.
reason: &'static str,
},
/// A clip plane or slab is malformed.
#[error("invalid clipping configuration: {reason}")]
InvalidClip {
/// Stable human-readable validation reason.
reason: &'static str,
},
/// A typed spatial or logical selection request is malformed.
#[error("invalid selection: {reason}")]
InvalidSelection {
/// Stable human-readable validation reason.
reason: &'static str,
},
/// A caller-supplied interaction record is malformed.
#[error("invalid molecular interaction: {reason}")]
InvalidInteraction {
/// Stable human-readable validation reason.
reason: &'static str,
},
/// Caller-supplied trajectory frames or time are malformed.
#[error("invalid trajectory segment: {reason}")]
InvalidTrajectory {
/// Stable human-readable validation reason.
reason: &'static str,
},
/// A caller-declared property mapping is malformed.
#[error("invalid property mapping: {reason}")]
InvalidProperty {
/// Stable human-readable validation reason.
reason: &'static str,
},
/// A typed attribute column or its target domain is malformed.
#[error("invalid attribute column: {reason}")]
InvalidAttribute {
/// Stable human-readable validation reason.
reason: &'static str,
},
/// A generic point, instance or relation batch is malformed.
#[error("invalid generic batch: {reason}")]
InvalidBatch {
/// Stable human-readable validation reason.
reason: &'static str,
},
/// A caller-authored annotation or measurement is malformed.
#[error("invalid annotation or measurement: {reason}")]
InvalidAnnotation {
/// Stable human-readable validation reason.
reason: &'static str,
},
/// A caller-supplied triangle mesh is malformed.
#[error("invalid mesh: {reason}")]
InvalidMesh {
/// Stable human-readable validation reason.
reason: &'static str,
},
/// A weighted ensemble has malformed membership or probabilities.
#[error("invalid ensemble: {reason}")]
InvalidEnsemble {
/// Stable human-readable validation reason.
reason: &'static str,
},
/// A caller-supplied structure correspondence or difference style is malformed.
#[error("invalid structural difference: {reason}")]
InvalidDifference {
/// Stable human-readable validation reason.
reason: &'static str,
},
/// A caller-supplied categorical label volume or style table is malformed.
#[error("invalid categorical segmentation: {reason}")]
InvalidSegmentation {
/// Stable human-readable validation reason.
reason: &'static str,
},
/// A scene manifest could not be encoded, decoded or matched to a scene.
#[error("invalid scene description: {summary}")]
InvalidSceneDescription {
/// Stable, caller-actionable diagnostic.
summary: String,
},
/// A caller-supplied analytic primitive is malformed.
#[error("invalid primitive: {reason}")]
InvalidPrimitive {
/// Stable validation reason.
reason: &'static str,
},
/// A screen overlay carries malformed geometry or scalar limits.
#[error("invalid screen overlay: {reason}")]
InvalidOverlay {
/// Stable validation reason.
reason: &'static str,
},
/// A timeline mapping, track or sample time is malformed.
#[error("invalid timeline: {reason}")]
InvalidTimeline {
/// Stable validation reason.
reason: &'static str,
},
/// A visual program is malformed or incompatible with its drawable.
#[error("invalid visual program: {summary}")]
InvalidVisual {
/// Stable caller-actionable diagnostic.
summary: String,
},
/// A representation was applied to an empty or invalid selection.
#[error("representation applied to an empty selection")]
EmptySelection,
/// A handle referred to an entry that no longer exists.
#[error("stale handle: the referenced entry was removed")]
StaleHandle,
/// The requested representation kind is not implemented yet.
#[error("representation kind {kind:?} is not available yet")]
Unsupported {
/// The kind that was requested.
kind: crate::representation::RepresentationKind,
},
}
impl From<crate::VisualError> for CoreError {
fn from(error: crate::VisualError) -> Self {
Self::InvalidVisual {
summary: error.to_string(),
}
}
}
impl CoreError {
/// The stable registry code for this condition.
#[must_use]
pub fn code(&self) -> &'static str {
match self {
Self::SurfaceComponentPolicy(_) => "MOLGFX-E0052",
Self::SpatialIndex(_) => "MOLGFX-E0051",
Self::StructureRead { .. } => "MOLGFX-E0030",
Self::AbsentAnnotation { .. } => "MOLGFX-E0031",
Self::InvalidVolume { .. } => "MOLGFX-E0032",
Self::InvalidClip { .. } => "MOLGFX-E0033",
Self::InvalidSelection { .. } => "MOLGFX-E0034",
Self::InvalidInteraction { .. } => "MOLGFX-E0035",
Self::InvalidTrajectory { .. } => "MOLGFX-E0036",
Self::InvalidProperty { .. } => "MOLGFX-E0037",
Self::InvalidAttribute { .. } => "MOLGFX-E0053",
Self::InvalidBatch { .. } => "MOLGFX-E0054",
Self::InvalidAnnotation { .. } => "MOLGFX-E0038",
Self::InvalidEnsemble { .. } => "MOLGFX-E0039",
Self::InvalidMesh { .. } => "MOLGFX-E0047",
Self::EmptySelection => "MOLGFX-E0040",
Self::StaleHandle => "MOLGFX-E0041",
Self::Unsupported { .. } => "MOLGFX-E0042",
Self::InvalidDifference { .. } => "MOLGFX-E0043",
Self::InvalidSegmentation { .. } => "MOLGFX-E0044",
Self::InvalidSceneDescription { .. } => "MOLGFX-E0045",
Self::InvalidPrimitive { .. } => "MOLGFX-E0046",
Self::InvalidOverlay { .. } => "MOLGFX-E0048",
Self::InvalidTimeline { .. } => "MOLGFX-E0049",
Self::InvalidVisual { .. } => "MOLGFX-E0050",
}
}
}