1
- use std:: fmt;
2
1
use std:: io;
3
2
4
3
/// Errors that occur when interacting with a remote process.
5
- #[ derive( Debug ) ]
4
+ #[ derive( Debug , thiserror :: Error ) ]
6
5
#[ non_exhaustive]
7
6
pub enum Error {
8
7
/// The master connection failed.
9
- Master ( io:: Error ) ,
8
+ #[ error( "the master connection failed" ) ]
9
+ Master ( #[ source] io:: Error ) ,
10
10
11
11
/// Failed to establish initial connection to the remote host.
12
- Connect ( io:: Error ) ,
12
+ #[ error( "failed to connect to the remote host" ) ]
13
+ Connect ( #[ source] io:: Error ) ,
13
14
14
15
/// Failed to run the `ssh` command locally.
15
16
#[ cfg( feature = "process-mux" ) ]
16
17
#[ cfg_attr( docsrs, doc( cfg( feature = "process-mux" ) ) ) ]
17
- Ssh ( io:: Error ) ,
18
+ #[ error( "the local ssh command could not be executed" ) ]
19
+ Ssh ( #[ source] io:: Error ) ,
18
20
19
21
/// Failed to connect to the ssh multiplex server.
20
22
#[ cfg( feature = "native-mux" ) ]
21
23
#[ cfg_attr( docsrs, doc( cfg( feature = "native-mux" ) ) ) ]
22
- SshMux ( openssh_mux_client:: Error ) ,
24
+ #[ error( "failed to connect to the ssh multiplex server" ) ]
25
+ SshMux ( #[ source] openssh_mux_client:: Error ) ,
23
26
24
27
/// Invalid command that contains null byte.
25
28
#[ cfg( feature = "native-mux" ) ]
26
29
#[ cfg_attr( docsrs, doc( cfg( feature = "native-mux" ) ) ) ]
30
+ #[ error( "invalid command: Command contains null byte." ) ]
27
31
InvalidCommand ,
28
32
29
33
/// The remote process failed.
30
- Remote ( io:: Error ) ,
34
+ #[ error( "the remote command could not be executed" ) ]
35
+ Remote ( #[ source] io:: Error ) ,
31
36
32
37
/// The connection to the remote host was severed.
33
38
///
@@ -36,6 +41,7 @@ pub enum Error {
36
41
///
37
42
/// You should call [`Session::check`](crate::Session::check) to verify if you get
38
43
/// this error back.
44
+ #[ error( "the connection was terminated" ) ]
39
45
Disconnected ,
40
46
41
47
/// Remote process is terminated.
@@ -51,13 +57,16 @@ pub enum Error {
51
57
/// instead of `Disconnect`ed.
52
58
///
53
59
/// It is thus recommended to create your own workaround for your particular use cases.
60
+ #[ error( "the remote process has terminated" ) ]
54
61
RemoteProcessTerminated ,
55
62
56
63
/// Failed to remove temporary dir where ssh socket and output is stored.
57
- Cleanup ( io:: Error ) ,
64
+ #[ error( "failed to remove temporary ssh session directory" ) ]
65
+ Cleanup ( #[ source] io:: Error ) ,
58
66
59
67
/// IO Error when creating/reading/writing from ChildStdin, ChildStdout, ChildStderr.
60
- ChildIo ( io:: Error ) ,
68
+ #[ error( "failure while accessing standard i/o of remote process" ) ]
69
+ ChildIo ( #[ source] io:: Error ) ,
61
70
}
62
71
63
72
#[ cfg( feature = "native-mux" ) ]
@@ -83,56 +92,6 @@ impl From<openssh_mux_client::Error> for Error {
83
92
}
84
93
}
85
94
86
- impl fmt:: Display for Error {
87
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
88
- match * self {
89
- Error :: Master ( _) => write ! ( f, "the master connection failed" ) ,
90
- Error :: Connect ( _) => write ! ( f, "failed to connect to the remote host" ) ,
91
-
92
- #[ cfg( feature = "process-mux" ) ]
93
- Error :: Ssh ( _) => write ! ( f, "the local ssh command could not be executed" ) ,
94
-
95
- Error :: Remote ( _) => write ! ( f, "the remote command could not be executed" ) ,
96
- Error :: Disconnected => write ! ( f, "the connection was terminated" ) ,
97
- Error :: Cleanup ( _) => write ! ( f, "failed to remove temporary ssh session directory" ) ,
98
- Error :: ChildIo ( _) => {
99
- write ! ( f, "failure while accessing standard I/O of remote process" )
100
- }
101
-
102
- Error :: RemoteProcessTerminated => write ! ( f, "the remote process has terminated" ) ,
103
-
104
- #[ cfg( feature = "native-mux" ) ]
105
- Error :: SshMux ( _) => write ! ( f, "failed to connect to the ssh multiplex server" ) ,
106
-
107
- #[ cfg( feature = "native-mux" ) ]
108
- Error :: InvalidCommand => write ! ( f, "invalid command: Command contains null byte." ) ,
109
- }
110
- }
111
- }
112
-
113
- impl std:: error:: Error for Error {
114
- fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
115
- match * self {
116
- Error :: Master ( ref e)
117
- | Error :: Connect ( ref e)
118
- | Error :: Remote ( ref e)
119
- | Error :: Cleanup ( ref e)
120
- | Error :: ChildIo ( ref e) => Some ( e) ,
121
-
122
- Error :: RemoteProcessTerminated | Error :: Disconnected => None ,
123
-
124
- #[ cfg( feature = "native-mux" ) ]
125
- Error :: InvalidCommand => None ,
126
-
127
- #[ cfg( feature = "process-mux" ) ]
128
- Error :: Ssh ( ref e) => Some ( e) ,
129
-
130
- #[ cfg( feature = "native-mux" ) ]
131
- Error :: SshMux ( ref e) => Some ( e) ,
132
- }
133
- }
134
- }
135
-
136
95
impl Error {
137
96
pub ( crate ) fn interpret_ssh_error ( stderr : & str ) -> Self {
138
97
// we want to turn the string-only ssh error into something a little more "handleable".
0 commit comments