printobserver_panels/
error.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum FrameField {
6 Resolution,
8 Stream,
10}
11
12impl FrameField {
13 #[must_use]
15 pub const fn as_str(self) -> &'static str {
16 match self {
17 Self::Resolution => "resolution",
18 Self::Stream => "stream",
19 }
20 }
21}
22
23#[derive(Debug, Clone, PartialEq)]
25pub enum ComposeError {
26 FrameMismatch {
30 field: FrameField,
32 expected: String,
34 got: String,
36 },
37 CameraMoved {
40 landmark: String,
42 offset_px: f64,
44 },
45 DriftUnverified,
48 OutlineOffFrame,
50 Undecodable {
52 detail: String,
54 },
55 Encode {
57 detail: String,
59 },
60}
61
62impl core::fmt::Display for ComposeError {
63 fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
64 match self {
65 Self::FrameMismatch {
66 field,
67 expected,
68 got,
69 } => write!(
70 formatter,
71 "the frame's {} is {got}, and the calibration's is {expected}",
72 field.as_str()
73 ),
74 Self::CameraMoved {
75 landmark,
76 offset_px,
77 } => write!(
78 formatter,
79 "the camera has moved since it was calibrated: {landmark} is {offset_px:.1} px from where it was"
80 ),
81 Self::DriftUnverified => formatter.write_str(
82 "fewer than two of the calibration's landmarks are visible, so whether the camera has moved is unknown",
83 ),
84 Self::OutlineOffFrame => {
85 formatter.write_str("nothing of the planned geometry lands in the frame")
86 }
87 Self::Undecodable { detail } => write!(formatter, "the frame is not a JPEG: {detail}"),
88 Self::Encode { detail } => write!(formatter, "the check image: {detail}"),
89 }
90 }
91}
92
93impl std::error::Error for ComposeError {}