@@ -2,7 +2,7 @@ use crate::cli::Timeout;
2
2
3
3
use super :: { IoStream , IoStreamSource } ;
4
4
5
- use anyhow:: { anyhow, ensure , Context , Error , Result } ;
5
+ use anyhow:: { anyhow, Context , Error , Result } ;
6
6
use bollard:: service:: EventMessage ;
7
7
use futures:: future:: { BoxFuture , Shared } ;
8
8
use tokio:: io:: AsyncWriteExt ;
@@ -139,16 +139,21 @@ impl Container {
139
139
let options = bollard:: container:: WaitContainerOptions {
140
140
condition : "not-running" ,
141
141
} ;
142
- let mut response = self . docker . wait_container ( self . id . as_str ( ) , Some ( options) ) ;
143
142
144
- let mut last = None ;
145
- while let Some ( wait_response) = response. next ( ) . await {
146
- last = Some ( wait_response?) ;
143
+ let response = self
144
+ . docker
145
+ . wait_container ( self . id . as_str ( ) , Some ( options) )
146
+ . next ( )
147
+ . await
148
+ . context ( "No response received for wait" ) ?;
149
+
150
+ match response {
151
+ Ok ( response) => Ok ( response. status_code ) ,
152
+ // If the container does not complete, e.g. it's killed, then we will receive
153
+ // an error code through docker.
154
+ Err ( bollard:: errors:: Error :: DockerContainerWaitError { error : _, code } ) => Ok ( code) ,
155
+ Err ( err) => Err ( err) ?,
147
156
}
148
-
149
- ensure ! ( last. is_some( ) , "Unexpected exit status" ) ;
150
-
151
- Ok ( last. unwrap ( ) . status_code )
152
157
}
153
158
154
159
pub async fn mkdir < T : AsRef < std:: path:: Path > > ( & self , path : T ) -> Result < ( ) > {
0 commit comments