1use core::fmt;
2use std::io;
3use std::net::Ipv4Addr;
4use std::process::ExitStatus;
5use std::time::Duration;
6
7use ql_qmi::codec::DecodeError;
8use ql_qmi::status::QmiError;
9
10use crate::digits::DigitsError;
11use crate::display::Chain;
12use crate::model::Model;
13use crate::system::CommandError;
14
15#[derive(thiserror::Error)]
20pub enum Failure {
21 #[error(transparent)]
23 Qmi(#[from] ql_qmi::Error),
24 #[error(transparent)]
26 Uim(#[from] ql_uim::Error),
27 #[error(transparent)]
29 Wds(#[from] ql_wds::Error),
30 #[error(transparent)]
32 Wms(#[from] ql_wms::Error),
33 #[error(transparent)]
35 Nas(#[from] ql_nas::Error),
36 #[error(transparent)]
38 Sleep(#[from] ql_sleep::Error),
39 #[error(transparent)]
41 Command(#[from] CommandError),
42 #[error("failed to start a runtime")]
44 Runtime(#[source] io::Error),
45 #[error("required services are missing: {}", names.join(", "))]
47 MissingServices {
48 names: Vec<&'static str>,
50 },
51 #[error("failed to decode the response to message {msg_id:#06x}")]
53 Decode {
54 msg_id: u16,
56 #[source]
58 source: DecodeError,
59 },
60 #[error("ql_manager answered the probe with {error}, expected success or ENCODING")]
62 UnexpectedProbe {
63 error: QmiError,
65 },
66 #[error("the probe says {probed}, the project version file says {expected}")]
68 ModelMismatch {
69 probed: Model,
71 expected: Model,
73 },
74 #[error("the {field} is missing")]
76 Missing {
77 field: &'static str,
79 },
80 #[error("{field} {value} is invalid")]
82 InvalidId {
83 field: &'static str,
85 value: String,
87 #[source]
89 source: DigitsError,
90 },
91 #[error("no card is present")]
93 NoCard,
94 #[error("no SMS arrived within {} s", timeout.as_secs())]
96 NoSms {
97 timeout: Duration,
99 },
100 #[error("failed to read {path}")]
102 Read {
103 path: &'static str,
105 #[source]
107 source: io::Error,
108 },
109 #[error("the wakeup source is {state} after the step {step}, expected {expected}")]
111 WakeupSource {
112 step: &'static str,
114 state: &'static str,
116 expected: &'static str,
118 },
119 #[error("autosleep is still on after the wake lock was dropped")]
121 AutosleepStillOn,
122 #[error("failed to read the interface addresses")]
124 Interfaces(#[source] nix::Error),
125 #[error("{interface} did not get {expected} within {} s", timeout.as_secs())]
127 AddressMissing {
128 interface: &'static str,
130 expected: Ipv4Addr,
132 timeout: Duration,
134 },
135 #[error("{interface} still has an IPv4 address after {} s", timeout.as_secs())]
137 AddressStays {
138 interface: &'static str,
140 timeout: Duration,
142 },
143 #[error("ping failed with {status}")]
145 Ping {
146 status: ExitStatus,
148 },
149 #[error("{command} failed with {status}")]
151 Exit {
152 command: &'static str,
154 status: ExitStatus,
156 },
157 #[error("failed to send a signal to {program}")]
159 Signal {
160 program: &'static str,
162 #[source]
164 source: nix::Error,
165 },
166 #[error("{program} is not {expected} after {} s", timeout.as_secs())]
168 Process {
169 program: &'static str,
171 expected: &'static str,
173 timeout: Duration,
175 },
176 #[error("wrong or missing messages: {}", cases.join(", "))]
178 Sms {
179 cases: Vec<&'static str>,
181 },
182}
183
184impl fmt::Debug for Failure {
185 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
186 Chain(self).fmt(f)
187 }
188}