1use thiserror::Error;
2
3type BoxError = Box<dyn core::error::Error + Send + Sync>;
4
5#[derive(Debug, Error)]
6#[error("{message}")]
7pub struct LinkError {
8 message: String,
9 #[source]
10 source: Option<BoxError>,
11}
12
13impl LinkError {
14 #[must_use]
15 pub fn new(message: impl Into<String>) -> Self {
16 Self {
17 message: message.into(),
18 source: None,
19 }
20 }
21
22 #[must_use]
23 pub fn with_source(message: impl Into<String>, source: impl Into<BoxError>) -> Self {
24 Self {
25 message: message.into(),
26 source: Some(source.into()),
27 }
28 }
29
30 #[must_use]
31 pub fn message(&self) -> &str {
32 &self.message
33 }
34}
35
36#[derive(Clone, Copy, Debug, PartialEq, Error)]
37#[non_exhaustive]
38pub enum EncodeError {
39 #[error("focus coordinate {axis} = {value} out of range {min}..={max}")]
40 FocusOutOfRange {
41 axis: &'static str,
42 value: i32,
43 min: i32,
44 max: i32,
45 },
46
47 #[error("transition margin {0:?} is out of range (0..=4294967295 ns)")]
48 TransitionMarginOutOfRange(core::time::Duration),
49
50 #[error(
51 "transition mode `Later` only writes a bank without transitioning, so it cannot be encoded into a transition"
52 )]
53 TransitionLaterNotEncodable,
54}