@@ -424,19 +424,20 @@ pub struct FileInfo {
424424 pub is_executable : bool ,
425425}
426426
427- //TODO: Make this TryFrom.
428- impl From < FileInfo > for FileNode {
429- fn from ( val : FileInfo ) -> Self {
430- let NameOrPath :: Name ( name) = val. name_or_path else {
431- panic ! (
427+ impl TryFrom < FileInfo > for FileNode {
428+ type Error = Error ;
429+
430+ fn try_from ( val : FileInfo ) -> Result < Self , Error > {
431+ match val. name_or_path {
432+ NameOrPath :: Path ( _) => Err ( make_input_err ! (
432433 "Cannot return a FileInfo that uses a NameOrPath::Path(), it must be a NameOrPath::Name()"
433- ) ;
434- } ;
435- Self {
436- name ,
437- digest : Some ( ( & val. digest ) . into ( ) ) ,
438- is_executable : val . is_executable ,
439- node_properties : Option :: default ( ) , // Not supported.
434+ ) ) ,
435+ NameOrPath :: Name ( name ) => Ok ( Self {
436+ name ,
437+ digest : Some ( ( & val . digest ) . into ( ) ) ,
438+ is_executable : val. is_executable ,
439+ node_properties : None , // Not supported.
440+ } ) ,
440441 }
441442 }
442443}
@@ -456,20 +457,21 @@ impl TryFrom<OutputFile> for FileInfo {
456457 }
457458}
458459
459- //TODO: Make this TryFrom.
460- impl From < FileInfo > for OutputFile {
461- fn from ( val : FileInfo ) -> Self {
462- let NameOrPath :: Path ( path) = val. name_or_path else {
463- panic ! (
460+ impl TryFrom < FileInfo > for OutputFile {
461+ type Error = Error ;
462+
463+ fn try_from ( val : FileInfo ) -> Result < Self , Error > {
464+ match val. name_or_path {
465+ NameOrPath :: Name ( _) => Err ( make_input_err ! (
464466 "Cannot return a FileInfo that uses a NameOrPath::Name(), it must be a NameOrPath::Path()"
465- ) ;
466- } ;
467- Self {
468- path ,
469- digest : Some ( ( & val. digest ) . into ( ) ) ,
470- is_executable : val . is_executable ,
471- contents : Bytes :: default ( ) ,
472- node_properties : Option :: default ( ) , // Not supported.
467+ ) ) ,
468+ NameOrPath :: Path ( path ) => Ok ( Self {
469+ path ,
470+ digest : Some ( ( & val . digest ) . into ( ) ) ,
471+ is_executable : val. is_executable ,
472+ contents : Bytes :: default ( ) ,
473+ node_properties : None , // Not supported.
474+ } ) ,
473475 }
474476 }
475477}
@@ -493,18 +495,19 @@ impl TryFrom<SymlinkNode> for SymlinkInfo {
493495 }
494496}
495497
496- // TODO: Make this TryFrom.
497- impl From < SymlinkInfo > for SymlinkNode {
498- fn from ( val : SymlinkInfo ) -> Self {
499- let NameOrPath :: Name ( name) = val. name_or_path else {
500- panic ! (
498+ impl TryFrom < SymlinkInfo > for SymlinkNode {
499+ type Error = Error ;
500+
501+ fn try_from ( val : SymlinkInfo ) -> Result < Self , Error > {
502+ match val. name_or_path {
503+ NameOrPath :: Path ( _) => Err ( make_input_err ! (
501504 "Cannot return a SymlinkInfo that uses a NameOrPath::Path(), it must be a NameOrPath::Name()"
502- ) ;
503- } ;
504- Self {
505- name ,
506- target : val . target ,
507- node_properties : Option :: default ( ) , // Not supported.
505+ ) ) ,
506+ NameOrPath :: Name ( name ) => Ok ( Self {
507+ name ,
508+ target : val . target ,
509+ node_properties : None , // Not supported.
510+ } ) ,
508511 }
509512 }
510513}
@@ -520,18 +523,21 @@ impl TryFrom<OutputSymlink> for SymlinkInfo {
520523 }
521524}
522525
523- // TODO: Make this TryFrom.
524- impl From < SymlinkInfo > for OutputSymlink {
525- fn from ( val : SymlinkInfo ) -> Self {
526- let NameOrPath :: Path ( path) = val. name_or_path else {
527- panic ! (
528- "Cannot return a SymlinkInfo that uses a NameOrPath::Path(), it must be a NameOrPath::Name()"
529- ) ;
530- } ;
531- Self {
532- path,
533- target : val. target ,
534- node_properties : Option :: default ( ) , // Not supported.
526+ impl TryFrom < SymlinkInfo > for OutputSymlink {
527+ type Error = Error ;
528+
529+ fn try_from ( val : SymlinkInfo ) -> Result < Self , Error > {
530+ match val. name_or_path {
531+ NameOrPath :: Path ( path) => {
532+ Ok ( Self {
533+ path,
534+ target : val. target ,
535+ node_properties : None , // Not supported.
536+ } )
537+ }
538+ NameOrPath :: Name ( _) => Err ( make_input_err ! (
539+ "Cannot return a SymlinkInfo that uses a NameOrPath::Name(), it must be a NameOrPath::Path()"
540+ ) ) ,
535541 }
536542 }
537543}
@@ -850,7 +856,7 @@ pub fn to_execute_response(action_result: ActionResult) -> ExecuteResponse {
850856 let message = action_result. message . clone ( ) ;
851857 ExecuteResponse {
852858 server_logs : logs_from ( action_result. server_logs . clone ( ) ) ,
853- result : Some ( action_result. into ( ) ) ,
859+ result : action_result. try_into ( ) . ok ( ) ,
854860 cached_result : false ,
855861 status,
856862 message,
@@ -880,35 +886,48 @@ impl From<ActionStage> for ExecuteResponse {
880886 }
881887}
882888
883- impl From < ActionResult > for ProtoActionResult {
884- fn from ( val : ActionResult ) -> Self {
889+ impl TryFrom < ActionResult > for ProtoActionResult {
890+ type Error = Error ;
891+
892+ fn try_from ( val : ActionResult ) -> Result < Self , Error > {
885893 let mut output_symlinks = Vec :: with_capacity (
886894 val. output_file_symlinks . len ( ) + val. output_directory_symlinks . len ( ) ,
887895 ) ;
888896 output_symlinks. extend_from_slice ( val. output_file_symlinks . as_slice ( ) ) ;
889897 output_symlinks. extend_from_slice ( val. output_directory_symlinks . as_slice ( ) ) ;
890898
891- Self {
892- output_files : val. output_files . into_iter ( ) . map ( Into :: into) . collect ( ) ,
899+ Ok ( Self {
900+ output_files : val
901+ . output_files
902+ . into_iter ( )
903+ . map ( TryInto :: try_into)
904+ . collect :: < Result < _ , _ > > ( ) ?,
893905 output_file_symlinks : val
894906 . output_file_symlinks
895907 . into_iter ( )
896- . map ( Into :: into)
897- . collect ( ) ,
898- output_symlinks : output_symlinks. into_iter ( ) . map ( Into :: into) . collect ( ) ,
899- output_directories : val. output_folders . into_iter ( ) . map ( Into :: into) . collect ( ) ,
908+ . map ( TryInto :: try_into)
909+ . collect :: < Result < _ , _ > > ( ) ?,
910+ output_symlinks : output_symlinks
911+ . into_iter ( )
912+ . map ( TryInto :: try_into)
913+ . collect :: < Result < _ , _ > > ( ) ?,
914+ output_directories : val
915+ . output_folders
916+ . into_iter ( )
917+ . map ( TryInto :: try_into)
918+ . collect :: < Result < _ , _ > > ( ) ?,
900919 output_directory_symlinks : val
901920 . output_directory_symlinks
902921 . into_iter ( )
903- . map ( Into :: into )
904- . collect ( ) ,
922+ . map ( TryInto :: try_into )
923+ . collect :: < Result < _ , _ > > ( ) ? ,
905924 exit_code : val. exit_code ,
906925 stdout_raw : Bytes :: default ( ) ,
907926 stdout_digest : Some ( val. stdout_digest . into ( ) ) ,
908927 stderr_raw : Bytes :: default ( ) ,
909928 stderr_digest : Some ( val. stderr_digest . into ( ) ) ,
910929 execution_metadata : Some ( val. execution_metadata . into ( ) ) ,
911- }
930+ } )
912931 }
913932}
914933
@@ -1026,7 +1045,7 @@ impl TryFrom<ExecuteResponse> for ActionStage {
10261045 } ;
10271046
10281047 if execute_response. cached_result {
1029- return Ok ( Self :: CompletedFromCache ( action_result. into ( ) ) ) ;
1048+ return Ok ( Self :: CompletedFromCache ( action_result. try_into ( ) ? ) ) ;
10301049 }
10311050 Ok ( Self :: Completed ( action_result) )
10321051 }
0 commit comments