1
- use std:: { num:: ParseIntError , str:: Utf8Error } ;
1
+ use std:: { fmt , num:: ParseIntError , str:: Utf8Error } ;
2
2
3
3
use super :: Message ;
4
4
@@ -22,6 +22,43 @@ pub enum Error {
22
22
ParseError ( Vec < Message > ) ,
23
23
}
24
24
25
+ impl fmt:: Display for Error {
26
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
27
+ match self {
28
+ Error :: IoError ( _) => write ! ( f, "IO operation failed" ) ,
29
+ Error :: ProtocolError ( msg) => {
30
+ write ! ( f, "received an error message from server" ) ?;
31
+ match msg {
32
+ Message :: ReplyTooLong ( _) => write ! ( f, ": reply too long" ) ,
33
+ Message :: RouteNotFound ( _) => write ! ( f, ": route not found" ) ,
34
+ Message :: ConfigurationFileError ( _) => write ! ( f, ": configuration file error" ) ,
35
+ Message :: NoProtocolsMatch ( _) => write ! ( f, ": no protocols match" ) ,
36
+ Message :: StoppedDueToReconfiguration ( _) => {
37
+ write ! ( f, ": stopped due to reconfiguration" )
38
+ }
39
+ Message :: ProtocolDown ( _) => write ! ( f, ": protocol is down => connot dump" ) ,
40
+ Message :: ReloadFailed ( _) => write ! ( f, ": reload failed" ) ,
41
+ Message :: AccessDenied ( _) => write ! ( f, ": access denied" ) ,
42
+ Message :: RuntimeError ( ..) => write ! ( f, ": evaluation runtime error" ) ,
43
+ _ => Ok ( ( ) ) ,
44
+ }
45
+ }
46
+ Error :: OperationInProgress => write ! ( f, "another request is already in progress" ) ,
47
+ Error :: InvalidToken ( _) => write ! ( f, "received invalid token" ) ,
48
+ Error :: ParseError ( _) => write ! ( f, "failed to parse server response" ) ,
49
+ }
50
+ }
51
+ }
52
+
53
+ impl std:: error:: Error for Error {
54
+ fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
55
+ match self {
56
+ Self :: IoError ( err) => Some ( err) ,
57
+ _ => None ,
58
+ }
59
+ }
60
+ }
61
+
25
62
impl Error {
26
63
pub fn eof ( err : & str ) -> Self {
27
64
Self :: IoError ( std:: io:: Error :: new ( std:: io:: ErrorKind :: UnexpectedEof , err) )
0 commit comments