forked from balena-os/wifi-connect
-
Notifications
You must be signed in to change notification settings - Fork 1
/
errors.rs
134 lines (109 loc) · 3.89 KB
/
errors.rs
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
use network_manager;
use network;
error_chain! {
foreign_links {
Io(::std::io::Error);
Recv(::std::sync::mpsc::RecvError);
SendNetworkCommand(::std::sync::mpsc::SendError<network::NetworkCommand>);
Nix(::nix::Error);
}
links {
NetworkManager(network_manager::errors::Error, network_manager::errors::ErrorKind);
}
errors {
RecvAccessPointSSIDs {
description("Receiving access point SSIDs failed")
}
SendAccessPointSSIDs {
description("Sending access point SSIDs failed")
}
SerializeAccessPointSSIDs {
description("Serializing access point SSIDs failed")
}
RecvNetworkCommand {
description("Receiving network command failed")
}
SendNetworkCommandActivate {
description("Sending NetworkCommand::Activate failed")
}
SendNetworkCommandConnect {
description("Sending NetworkCommand::Connect failed")
}
DeviceByInterface(interface: String) {
description("Cannot find network device with interface name")
display("Cannot find network device with interface name '{}'", interface)
}
NotAWiFiDevice(interface: String) {
description("Not a WiFi device")
display("Not a WiFi device: {}", interface)
}
UnmanagedDevice(interface: String) {
description("Unmanaged device")
display("Unmanaged device: {}", interface)
}
NoWiFiDevice {
description("Cannot find a WiFi device")
}
NoAccessPoints {
description("Getting access points failed")
}
CreateCaptivePortal {
description("Creating the captive portal failed")
}
StopAccessPoint {
description("Stopping the access point failed")
}
DeleteAccessPoint {
description("Deleting access point connection profile failed")
}
StartHTTPServer(address: String, reason: String) {
description("Cannot start HTTP server")
display("Cannot start HTTP server on '{}': {}", address, reason)
}
StartActiveNetworkManager {
description("Starting the NetworkManager service with active state failed")
}
StartNetworkManager {
description("Starting the NetworkManager service failed")
}
Dnsmasq {
description("Spawning dnsmasq failed")
}
BlockExitSignals {
description("Blocking exit signals failed")
}
TrapExitSignals {
description("Trapping exit signals failed")
}
RootPrivilegesRequired(app: String) {
description("Root privileges required")
display("You need root privileges to run {}", app)
}
}
}
pub fn exit_code(e: &Error) -> i32 {
match *e.kind() {
ErrorKind::Dnsmasq => 3,
ErrorKind::RecvAccessPointSSIDs => 4,
ErrorKind::SendAccessPointSSIDs => 5,
ErrorKind::SerializeAccessPointSSIDs => 6,
ErrorKind::RecvNetworkCommand => 7,
ErrorKind::SendNetworkCommandActivate => 8,
ErrorKind::SendNetworkCommandConnect => 9,
ErrorKind::DeviceByInterface(_) => 10,
ErrorKind::NotAWiFiDevice(_) => 11,
ErrorKind::NoWiFiDevice => 12,
ErrorKind::NoAccessPoints => 13,
ErrorKind::CreateCaptivePortal => 14,
ErrorKind::StopAccessPoint => 15,
ErrorKind::DeleteAccessPoint => 16,
ErrorKind::StartHTTPServer(_, _) => 17,
ErrorKind::StartActiveNetworkManager => 18,
ErrorKind::StartNetworkManager => 19,
ErrorKind::BlockExitSignals => 21,
ErrorKind::TrapExitSignals => 22,
ErrorKind::RootPrivilegesRequired(_) => 23,
ErrorKind::UnmanagedDevice(_) => 24,
_ => 1,
}
}