1- use std:: { io :: Error , path:: PathBuf } ;
1+ use std:: path:: PathBuf ;
22
33use crate :: {
4- compose:: client:: { ComposeInterface , DownCommand , UpCommand } ,
4+ compose:: {
5+ client:: { ComposeInterface , DownCommand , UpCommand } ,
6+ error:: Result ,
7+ } ,
58 core:: { CmdWaitFor , ExecCommand , Mount } ,
69 images:: docker_cli:: DockerCli ,
710 runners:: AsyncRunner ,
@@ -14,7 +17,7 @@ pub(crate) struct ContainerisedComposeCli {
1417}
1518
1619impl ContainerisedComposeCli {
17- pub ( super ) async fn new ( compose_files : Vec < PathBuf > ) -> Self {
20+ pub ( super ) async fn new ( compose_files : Vec < PathBuf > ) -> Result < Self > {
1821 let mut image = ContainerRequest :: from ( DockerCli :: new ( "/var/run/docker.sock" ) ) ;
1922
2023 let compose_files_in_container: Vec < String > = compose_files
@@ -25,24 +28,24 @@ impl ContainerisedComposeCli {
2528 let mounts: Vec < _ > = compose_files
2629 . iter ( )
2730 . zip ( compose_files_in_container. iter ( ) )
28- . map ( |( path, file_name) | Mount :: bind_mount ( path. to_str ( ) . unwrap ( ) , file_name) )
31+ . filter_map ( |( path, file_name) | path. to_str ( ) . map ( |p| Mount :: bind_mount ( p , file_name) ) )
2932 . collect ( ) ;
3033
3134 for mount in mounts {
3235 image = image. with_mount ( mount) ;
3336 }
3437
35- let container = image. start ( ) . await . expect ( "TODO: Handle error" ) ;
38+ let container = image. start ( ) . await ? ;
3639
37- Self {
40+ Ok ( Self {
3841 container,
3942 compose_files_in_container,
40- }
43+ } )
4144 }
4245}
4346
4447impl ComposeInterface for ContainerisedComposeCli {
45- async fn up ( & self , command : UpCommand ) -> Result < ( ) , Error > {
48+ async fn up ( & self , command : UpCommand ) -> Result < ( ) > {
4649 let mut cmd = vec ! [
4750 "docker" . to_string( ) ,
4851 "compose" . to_string( ) ,
@@ -71,13 +74,12 @@ impl ComposeInterface for ContainerisedComposeCli {
7174 cmd. push ( command. wait_timeout . as_secs ( ) . to_string ( ) ) ;
7275
7376 let exec = ExecCommand :: new ( cmd) ;
74- // todo: error handling
75- self . container . exec ( exec) . await . map_err ( Error :: other) ?;
77+ self . container . exec ( exec) . await ?;
7678
7779 Ok ( ( ) )
7880 }
7981
80- async fn down ( & self , command : DownCommand ) -> Result < ( ) , Error > {
82+ async fn down ( & self , command : DownCommand ) -> Result < ( ) > {
8183 let mut cmd = vec ! [
8284 "docker" . to_string( ) ,
8385 "compose" . to_string( ) ,
@@ -94,7 +96,7 @@ impl ComposeInterface for ContainerisedComposeCli {
9496 }
9597
9698 let exec = ExecCommand :: new ( cmd) . with_cmd_ready_condition ( CmdWaitFor :: exit_code ( 0 ) ) ;
97- self . container . exec ( exec) . await . map_err ( Error :: other ) ?;
99+ self . container . exec ( exec) . await ?;
98100 Ok ( ( ) )
99101 }
100102}
0 commit comments