@@ -91,7 +91,12 @@ async fn main() -> Result<(), anyhow::Error> {
9191 } ;
9292 let p = Path :: new ( & file) ;
9393 info ! ( "Uploading {}" , file) ;
94- process_file ( p, & bucket) . await ;
94+ match process_file ( p, & bucket) . await {
95+ Ok ( ( ) ) => ( ) ,
96+ Err ( e) => {
97+ error ! ( "File processing failed: {e}" ) ;
98+ }
99+ } ;
95100 } else {
96101 info ! ( "Uploading all content in {}" , core_dir_command) ;
97102 run_polling_agent ( false ) . await ;
@@ -320,53 +325,37 @@ async fn process_file(zip_path: &Path, bucket: &Bucket) -> Result<(), String> {
320325 } else {
321326 error ! ( "File locked on INotify shouldn't happen as we are waiting for file close events.\n Please recycling pod to perform sweep\n {}" , e) ;
322327 }
323- return ;
328+ return Err ( "File locked" . into ( ) ) ;
324329 }
325330 }
326331
327- let metadata = fs:: metadata ( zip_path) . expect ( "unable to read metadata" ) ;
332+ let metadata = fs:: metadata ( zip_path) . map_err ( |e| format ! ( "unable to read metadata: {e}" ) ) ? ;
328333 info ! ( "zip size is {}" , metadata. len( ) ) ;
329- let path_str = match zip_path. to_str ( ) {
330- Some ( v) => v,
331- None => {
332- error ! ( "Failed to extract path" ) ;
333- return ;
334- }
335- } ;
336- let upload_file_name: & str = match zip_path. file_name ( ) . unwrap ( ) . to_str ( ) {
337- Some ( v) => v,
338- None => {
339- error ! ( "Failed to get file name for upload" ) ;
340- return ;
341- }
342- } ;
334+ let path_str = zip_path. to_str ( ) . ok_or ( "Failed to extract path" ) ?;
335+ let upload_file_name: & str = zip_path
336+ . file_name ( )
337+ . ok_or ( "Failed to get file name for upload" ) ?
338+ . to_str ( )
339+ . ok_or ( "Invalid encoding of file name for upload" ) ?;
343340
344341 let mut fasync = tokio:: fs:: File :: open ( zip_path)
345342 . await
346- . expect ( "file was removed" ) ;
343+ . map_err ( |e| format ! ( "file became unavailable while processing: {e}" ) ) ? ;
347344
348- let code = match bucket
345+ let code = bucket
349346 . put_object_stream ( & mut fasync, upload_file_name)
350347 . await
351- {
352- Ok ( v) => v,
353- Err ( e) => {
354- error ! ( "Upload Failed {}" , e) ;
355- return ;
356- }
357- } ;
358- match fs:: remove_file ( path_str) {
359- Ok ( v) => v,
360- Err ( e) => {
361- error ! ( "File delete failed: {}" , e) ;
362- return ;
363- }
364- } ;
348+ . map_err ( |e| format ! ( "Upload Failed: {e:?}" ) ) ?;
349+
350+ fs:: remove_file ( path_str) . map_err ( |e| format ! ( "File delete failed: {}" , e) ) ?;
351+
365352 info ! (
366353 "S3 Returned: status_code: {} uploaded_bytes: {}" ,
367354 code. status_code( ) ,
368355 code. uploaded_bytes( )
369356 ) ;
357+
358+ Ok ( ( ) )
370359}
371360
372361fn get_bucket ( ) -> Result < Box < Bucket > , anyhow:: Error > {
0 commit comments