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
//! Errors specific to the CoreDevice services.
use thiserror::Error;
/// Failures specific to talking to the device's CoreDevice services.
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum CoreDeviceError {
/// The device returned an error envelope instead of the expected output
/// (typically a populated `CoreDevice.error` in the response). The string is
/// the device's own error detail.
#[error("device returned an error: {0}")]
DeviceError(String),
/// A field the response was required to contain was absent.
#[error("device response missing required field `{0}`")]
MissingField(&'static str),
/// A field was present but had a type or shape we couldn't interpret.
#[error("device response field `{0}` had an unexpected type or shape")]
MalformedField(&'static str),
/// An AVConference media negotiation blob (offer/answer) failed to encode or
/// decode.
#[error("media negotiation blob error: {0}")]
Negotiation(String),
/// A touchscreen report contained more contacts than the device supports.
#[error("touchscreen report has {0} contacts; at most 5 are supported")]
TooManyTouchscreenContacts(usize),
/// A touchscreen contact identity was outside the supported range.
#[error("touchscreen contact identity {0} is outside 0..5")]
InvalidTouchscreenContactIdentity(u8),
/// A touchscreen report used the same contact identity more than once.
#[error("touchscreen contact identity {0} is duplicated")]
DuplicateTouchscreenContactIdentity(u8),
/// A multi-touch tap was requested without any contact positions.
#[error("multi-touch tap requires at least one contact")]
NoTouchscreenContacts,
/// A caller-supplied argument was outside the range the device accepts.
#[error("invalid argument: {0}")]
InvalidArgument(&'static str),
}
impl CoreDeviceError {
pub fn sub_code(&self) -> i32 {
match self {
Self::DeviceError(_) => 1,
Self::MissingField(_) => 2,
Self::MalformedField(_) => 3,
Self::Negotiation(_) => 4,
Self::TooManyTouchscreenContacts(_) => 5,
Self::InvalidTouchscreenContactIdentity(_) => 6,
Self::DuplicateTouchscreenContactIdentity(_) => 7,
Self::NoTouchscreenContacts => 8,
Self::InvalidArgument(_) => 9,
}
}
}