Skip to main content

scena/diagnostics/display/
lookup.rs

1use std::fmt;
2
3use super::LookupError;
4
5impl fmt::Display for LookupError {
6    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
7        match self {
8            Self::NoActiveCamera => write!(
9                formatter,
10                "scene has no active camera; call Scene::add_default_camera or Scene::set_active_camera"
11            ),
12            Self::NodeNotFound(_) => write!(formatter, "node key does not exist in the scene"),
13            Self::CannotRemoveRootNode(_) => {
14                write!(formatter, "the scene root node cannot be removed")
15            }
16            Self::NodeNameNotFound { name, candidates } => {
17                write_missing_with_candidates(formatter, "node", name, candidates)
18            }
19            Self::AmbiguousNodeName { name, matches } => write!(
20                formatter,
21                "imported scene node name '{name}' is ambiguous across {} nodes",
22                matches.len()
23            ),
24            Self::AnchorNotFound { name, candidates } => {
25                write_missing_with_candidates(formatter, "anchor", name, candidates)
26            }
27            Self::AmbiguousAnchorName { name, hosts } => write!(
28                formatter,
29                "imported scene anchor name '{name}' is ambiguous across {} host nodes",
30                hosts.len()
31            ),
32            Self::ConnectorNotFound { name, candidates } => {
33                write_missing_with_candidates(formatter, "connector", name, candidates)
34            }
35            Self::AmbiguousConnectorName { name, hosts } => write!(
36                formatter,
37                "imported scene connector name '{name}' is ambiguous across {} host nodes",
38                hosts.len()
39            ),
40            Self::ClipNotFound { name, candidates } => {
41                write_missing_with_candidates(formatter, "animation clip", name, candidates)
42            }
43            Self::VariantNotFound { name, candidates } => write_missing_with_candidates(
44                formatter,
45                "KHR_materials_variants variant",
46                name,
47                candidates,
48            ),
49            Self::AmbiguousVariantName { name, matches } => write!(
50                formatter,
51                "imported scene KHR_materials_variants name '{name}' is ambiguous across {} variants",
52                matches.len()
53            ),
54            Self::AmbiguousClipName { name, matches } => write!(
55                formatter,
56                "imported scene animation clip name '{name}' is ambiguous across {} clips",
57                matches.len()
58            ),
59            Self::PathNotFound { path } => {
60                write!(formatter, "imported scene path '{path}' was not found")
61            }
62            Self::InvalidViewport { width, height } => write!(
63                formatter,
64                "viewport {width}x{height} is invalid; width and height must be non-zero"
65            ),
66            Self::InvalidBounds { reason } => write!(formatter, "bounds are invalid: {reason}"),
67            Self::InvalidFramingOption { field, reason } => write!(
68                formatter,
69                "camera framing option '{field}' is invalid: {reason}"
70            ),
71            Self::UnsupportedCameraType {
72                camera,
73                operation,
74                supported,
75            } => write!(
76                formatter,
77                "{operation} does not support camera {camera:?}; supported camera type: {supported}"
78            ),
79            Self::ImportHasNoBounds => write!(
80                formatter,
81                "imported scene has no renderable bounds to frame"
82            ),
83            Self::StaleImport => write!(formatter, "scene import has been invalidated"),
84            Self::ImportFromDifferentScene => {
85                write!(formatter, "scene import belongs to a different scene")
86            }
87            Self::NodeIsNotMesh { node } => write!(formatter, "node {node:?} is not a mesh node"),
88            Self::NonInvertibleParentTransform { node, parent } => write!(
89                formatter,
90                "node {node:?} cannot be placed in world space because parent {parent:?} has a non-invertible transform"
91            ),
92            Self::InvalidMorphWeights { node, reason } => {
93                write!(
94                    formatter,
95                    "morph weights for node {node:?} are invalid: {reason}"
96                )
97            }
98            Self::MorphWeightWidthMismatch {
99                node,
100                expected,
101                supplied,
102            } => write!(
103                formatter,
104                "node {node:?} expects {expected} morph weights but {supplied} were supplied"
105            ),
106            Self::InvalidTransform { reason } => {
107                write!(formatter, "transform is invalid: {reason}")
108            }
109            Self::InvalidCameraProjection { reason } => {
110                write!(formatter, "camera projection is invalid: {reason}")
111            }
112            Self::GeometryNotFound { node, .. } => write!(
113                formatter,
114                "geometry for mesh node {node:?} was not found in Assets"
115            ),
116            Self::InvalidSkinBinding {
117                joint_count,
118                inverse_bind_count,
119            } => write!(
120                formatter,
121                "skin binding has {joint_count} joints but {inverse_bind_count} inverse bind matrices"
122            ),
123            Self::CameraNotFound(_) => write!(formatter, "camera key does not exist in the scene"),
124            Self::ClippingPlaneNotFound(_) => {
125                write!(formatter, "clipping plane key does not exist in the scene")
126            }
127            Self::InstanceSetNotFound(_) => {
128                write!(formatter, "instance set key does not exist in the scene")
129            }
130            Self::ParticleSetNotFound(_) => {
131                write!(formatter, "particle set key does not exist in the scene")
132            }
133            Self::InstanceNotFound {
134                instance_set,
135                instance,
136            } => write!(
137                formatter,
138                "instance {:?} does not exist in instance set {:?}",
139                instance, instance_set
140            ),
141            Self::InvalidInstanceTint {
142                instance_set,
143                instance,
144                reason,
145            } => write!(
146                formatter,
147                "instance {:?} in instance set {:?} has invalid tint: {reason}",
148                instance, instance_set
149            ),
150            Self::LabelNotFound(_) => write!(formatter, "label key does not exist in the scene"),
151            Self::UnsupportedLabelText { reason, .. } => write!(
152                formatter,
153                "label text is not supported by its font: {reason}"
154            ),
155            Self::InvalidLabelStyle { field, reason } => {
156                write!(formatter, "{field} is not supported: {reason}")
157            }
158        }
159    }
160}
161
162fn write_missing_with_candidates(
163    formatter: &mut fmt::Formatter<'_>,
164    kind: &str,
165    name: &str,
166    candidates: &[String],
167) -> fmt::Result {
168    write!(formatter, "imported scene has no {kind} named '{name}'")?;
169    if !candidates.is_empty() {
170        write!(formatter, "; nearest candidates: {}", candidates.join(", "))?;
171    }
172    Ok(())
173}