@@ -33,6 +33,7 @@ pub enum ErrorKind {
3333 InvalidConnectionState ( ConnectionState ) ,
3434
3535 IOError ( Arc < io:: Error > ) ,
36+ RuntimeShutdownError ( Arc < io:: Error > ) ,
3637 ParsingError ( ParserError ) ,
3738 ProtocolError ( AMQPError ) ,
3839 SerialisationError ( Arc < GenError > ) ,
@@ -43,7 +44,15 @@ pub enum ErrorKind {
4344
4445impl Error {
4546 pub ( crate ) fn other < E : Into < Box < dyn error:: Error + Send + Sync > > > ( error : E ) -> Self {
46- ErrorKind :: IOError ( Arc :: new ( io:: Error :: other ( error) ) ) . into ( )
47+ io:: Error :: other ( error) . into ( )
48+ }
49+
50+ pub ( crate ) fn io ( error : io:: Error ) -> Self {
51+ if io_error_is_runtime_shutdown ( & error) {
52+ ErrorKind :: RuntimeShutdownError ( Arc :: new ( error) ) . into ( )
53+ } else {
54+ error. into ( )
55+ }
4756 }
4857
4958 pub fn kind ( & self ) -> & ErrorKind {
@@ -79,6 +88,13 @@ impl Error {
7988 if let ErrorKind :: IOError ( _) = self . kind ( ) {
8089 return true ;
8190 }
91+ self . is_runtime_shutdown_error ( )
92+ }
93+
94+ pub fn is_runtime_shutdown_error ( & self ) -> bool {
95+ if let ErrorKind :: RuntimeShutdownError ( _) = self . kind ( ) {
96+ return true ;
97+ }
8298 false
8399 }
84100
@@ -107,13 +123,6 @@ impl Error {
107123 false
108124 }
109125
110- pub fn is_runtime_shutdown_error ( & self ) -> bool {
111- if let ErrorKind :: IOError ( e) = self . kind ( ) {
112- return io_error_is_runtime_shutdown ( e) ;
113- }
114- false
115- }
116-
117126 pub fn can_be_recovered ( & self ) -> bool {
118127 match self . kind ( ) {
119128 ErrorKind :: ChannelsLimitReached => false ,
@@ -123,7 +132,8 @@ impl Error {
123132 ErrorKind :: InvalidChannelState ( ..) => true ,
124133 ErrorKind :: InvalidConnectionState ( _) => true ,
125134
126- ErrorKind :: IOError ( e) => !io_error_is_runtime_shutdown ( e) ,
135+ ErrorKind :: IOError ( _) => true ,
136+ ErrorKind :: RuntimeShutdownError ( _) => false ,
127137 ErrorKind :: ParsingError ( _) => false ,
128138 ErrorKind :: ProtocolError ( _) => true ,
129139 ErrorKind :: SerialisationError ( _) => false ,
@@ -166,6 +176,7 @@ impl fmt::Display for Error {
166176 }
167177
168178 ErrorKind :: IOError ( e) => write ! ( f, "IO error: {e}" ) ,
179+ ErrorKind :: RuntimeShutdownError ( e) => write ! ( f, "runtime shutdown error: {e}" ) ,
169180 ErrorKind :: ParsingError ( e) => write ! ( f, "failed to parse: {e}" ) ,
170181 ErrorKind :: ProtocolError ( e) => write ! ( f, "protocol error: {e}" ) ,
171182 ErrorKind :: SerialisationError ( e) => write ! ( f, "failed to serialise: {e}" ) ,
@@ -182,6 +193,7 @@ impl error::Error for Error {
182193 fn source ( & self ) -> Option < & ( dyn error:: Error + ' static ) > {
183194 match self . kind ( ) {
184195 ErrorKind :: IOError ( e) => Some ( & * * e) ,
196+ ErrorKind :: RuntimeShutdownError ( e) => Some ( & * * e) ,
185197 ErrorKind :: ParsingError ( e) => Some ( e) ,
186198 ErrorKind :: ProtocolError ( e) => Some ( e) ,
187199 ErrorKind :: SerialisationError ( e) => Some ( & * * e) ,
@@ -229,6 +241,10 @@ impl PartialEq for Error {
229241 error ! ( "Unable to compare lapin::ErrorKind::IOError" ) ;
230242 false
231243 }
244+ ( RuntimeShutdownError ( _) , RuntimeShutdownError ( _) ) => {
245+ error ! ( "Unable to compare lapin::ErrorKind::RuntimeShutdownError" ) ;
246+ false
247+ }
232248 ( ParsingError ( left_inner) , ParsingError ( right_inner) ) => left_inner == right_inner,
233249 ( ProtocolError ( left_inner) , ProtocolError ( right_inner) ) => left_inner == right_inner,
234250 ( SerialisationError ( _) , SerialisationError ( _) ) => {
0 commit comments