aboutsummaryrefslogtreecommitdiffstats
path: root/src/error.rs
blob: 42135d8b8b2313baaf33fe711b3cf88952019fa8 (plain) (blame)
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#[derive(Debug, snafu::Snafu)]
#[snafu(visibility = "pub")]
pub enum Error {
    #[snafu(display("failed to accept: {}", source))]
    Acceptor { source: tokio::io::Error },

    #[snafu(display("failed to bind: {}", source))]
    Bind { source: tokio::io::Error },

    #[snafu(display("failed to connect: {}", source))]
    Connect { source: std::io::Error },

    #[snafu(display("failed to connect: {}", source))]
    ConnectTls { source: native_tls::Error },

    #[snafu(display("couldn't find username"))]
    CouldntFindUsername,

    #[snafu(display("failed to create tls acceptor: {}", source))]
    CreateAcceptor { source: native_tls::Error },

    #[snafu(display("failed to create tls connector: {}", source))]
    CreateConnector { source: native_tls::Error },

    #[snafu(display("eof"))]
    EOF,

    #[snafu(display("failed to parse string: {:?}", data))]
    ExtraMessageData { data: Vec<u8> },

    #[snafu(display("failed to write to stdout: {}", source))]
    FlushTerminal { source: tokio::io::Error },

    #[snafu(display("failed to flush writes to terminal: {}", source))]
    FlushTerminalSync { source: std::io::Error },

    #[snafu(display("failed to get terminal size: {}", source))]
    GetTerminalSize { source: crossterm::ErrorKind },

    #[snafu(display("failed to find any resolved addresses"))]
    HasResolvedAddr,

    #[snafu(display("invalid auth type: {}", ty))]
    InvalidAuthType { ty: u32 },

    #[snafu(display("invalid message type: {}", ty))]
    InvalidMessageType { ty: u32 },

    #[snafu(display("invalid watch id: {}", id))]
    InvalidWatchId { id: String },

    #[snafu(display(
        "packet length must be at least {} bytes (got {})",
        expected,
        len
    ))]
    LenTooSmall { len: u32, expected: usize },

    #[snafu(display(
        "packet length must be at most {} bytes (got {})",
        expected,
        len
    ))]
    LenTooBig { len: u32, expected: usize },

    #[snafu(display("couldn't find name in argv"))]
    MissingArgv,

    #[snafu(display(
        "detected argv path was not a valid filename: {}",
        path
    ))]
    NotAFileName { path: String },

    #[snafu(display("failed to open file: {}", source))]
    OpenFile { source: tokio::io::Error },

    #[snafu(display("failed to open identity file: {}", source))]
    OpenIdentityFile { source: std::io::Error },

    #[snafu(display("failed to open a pty: {}", source))]
    OpenPty { source: std::io::Error },

    #[snafu(display("failed to parse address"))]
    ParseAddress,

    #[snafu(display("failed to parse address: {}", source))]
    ParseAddr { source: std::net::AddrParseError },

    #[snafu(display("{}", source))]
    ParseArgs { source: clap::Error },

    #[snafu(display("failed to parse buffer size '{}': {}", input, source))]
    ParseBufferSize {
        input: String,
        source: std::num::ParseIntError,
    },

    #[snafu(display("failed to parse identity file: {}", source))]
    ParseIdentity { source: native_tls::Error },

    #[snafu(display("failed to parse int: {}", source))]
    ParseInt {
        source: std::array::TryFromSliceError,
    },

    #[snafu(display("failed to parse address: {}", source))]
    ParsePort { source: std::num::ParseIntError },

    #[snafu(display(
        "failed to parse read timeout '{}': {}",
        input,
        source
    ))]
    ParseReadTimeout {
        input: String,
        source: std::num::ParseIntError,
    },

    #[snafu(display("failed to parse string: {}", source))]
    ParseString { source: std::string::FromUtf8Error },

    #[snafu(display("failed to poll for process exit: {}", source))]
    ProcessExitPoll { source: std::io::Error },

    #[snafu(display("rate limit exceeded"))]
    RateLimited,

    #[snafu(display("failed to read from event channel: {}", source))]
    ReadChannel {
        source: tokio::sync::mpsc::error::UnboundedRecvError,
    },

    #[snafu(display("failed to read from file: {}", source))]
    ReadFile { source: tokio::io::Error },

    #[snafu(display("failed to read identity file: {}", source))]
    ReadIdentityFile { source: std::io::Error },

    #[snafu(display("{}", source))]
    ReadMessageWithTimeout {
        #[snafu(source(from(tokio::timer::timeout::Error<Error>, Box::new)))]
        source: Box<tokio::timer::timeout::Error<Error>>,
    },

    #[snafu(display("failed to read packet: {}", source))]
    ReadPacket { source: std::io::Error },

    #[snafu(display("failed to read packet: {}", source))]
    ReadPacketAsync { source: tokio::io::Error },

    #[snafu(display("failed to read from pty: {}", source))]
    ReadPty { source: std::io::Error },

    #[snafu(display("failed to read from terminal: {}", source))]
    ReadTerminal { source: std::io::Error },

    #[snafu(display("failed to resize pty: {}", source))]
    ResizePty { source: std::io::Error },

    #[snafu(display("failed to resolve address: {}", source))]
    ResolveAddress { source: std::io::Error },

    #[snafu(display(
        "failed to send accepted socket to server thread: {}",
        source
    ))]
    SendSocketChannel {
        source: tokio::sync::mpsc::error::TrySendError<tokio::net::TcpStream>,
    },

    #[snafu(display("failed to send accepted socket to server thread"))]
    SendSocketChannelTls {
        // XXX tokio_tls::Accept doesn't implement Debug or Display
    // source: tokio::sync::mpsc::error::TrySendError<tokio_tls::Accept<tokio::net::TcpStream>>,
    },

    #[snafu(display("received error from server: {}", message))]
    Server { message: String },

    #[snafu(display("SIGWINCH handler failed: {}", source))]
    SigWinchHandler { source: std::io::Error },

    #[snafu(display("failed to sleep until next frame: {}", source))]
    Sleep { source: tokio::timer::Error },

    #[snafu(display(
        "failed to receive new socket over channel: channel closed"
    ))]
    SocketChannelClosed,

    #[snafu(display(
        "failed to receive new socket over channel: {}",
        source
    ))]
    SocketChannelReceive {
        source: tokio::sync::mpsc::error::RecvError,
    },

    #[snafu(display("failed to spawn process for `{}`: {}", cmd, source))]
    SpawnProcess { cmd: String, source: std::io::Error },

    #[snafu(display(
        "failed to spawn a background thread to read terminal input: {}",
        source
    ))]
    TerminalInputReadingThread { source: std::io::Error },

    #[snafu(display(
        "terminal must be smaller than 1000 rows or columns (got {})",
        size
    ))]
    TermTooBig { size: crate::term::Size },

    #[snafu(display("timeout"))]
    Timeout,

    #[snafu(display("heartbeat timer failed: {}", source))]
    TimerHeartbeat { source: tokio::timer::Error },

    #[snafu(display("read timeout timer failed: {}", source))]
    TimerReadTimeout { source: tokio::timer::Error },

    #[snafu(display("reconnect timer failed: {}", source))]
    TimerReconnect { source: tokio::timer::Error },

    #[snafu(display("failed to switch to alternate screen: {}", source))]
    ToAlternateScreen { source: crossterm::ErrorKind },

    #[snafu(display(
        "failed to put the terminal into raw mode: {}",
        source
    ))]
    ToRawMode { source: crossterm::ErrorKind },

    #[snafu(display("unauthenticated message: {:?}", message))]
    UnauthenticatedMessage { message: crate::protocol::Message },

    #[snafu(display("unexpected message: {:?}", message))]
    UnexpectedMessage { message: crate::protocol::Message },

    #[snafu(display("failed to write to event channel: {}", source))]
    WriteChannel {
        source: tokio::sync::mpsc::error::UnboundedSendError,
    },

    #[snafu(display("failed to write to file: {}", source))]
    WriteFile { source: tokio::io::Error },

    #[snafu(display("{}", source))]
    WriteMessageWithTimeout {
        #[snafu(source(from(tokio::timer::timeout::Error<Error>, Box::new)))]
        source: Box<tokio::timer::timeout::Error<Error>>,
    },

    #[snafu(display("failed to write packet: {}", source))]
    WritePacket { source: std::io::Error },

    #[snafu(display("failed to write packet: {}", source))]
    WritePacketAsync { source: tokio::io::Error },

    #[snafu(display("failed to write to pty: {}", source))]
    WritePty { source: std::io::Error },

    #[snafu(display("failed to write to stdout: {}", source))]
    WriteTerminal { source: tokio::io::Error },

    #[snafu(display("failed to write to terminal: {}", source))]
    WriteTerminalCrossterm { source: crossterm::ErrorKind },

    #[snafu(display("failed to write to terminal: {}", source))]
    WriteTerminalSync { source: std::io::Error },
}

pub type Result<T> = std::result::Result<T, Error>;