@@ -114,6 +114,9 @@ func (s *S3Cache) processPackages(ctx context.Context, pkgs []cache.Package, fn
114114 }
115115
116116 if len (errs ) > 0 {
117+ // For upload operations, we want to log errors but not fail the entire build
118+ // This is determined by the caller (Upload vs Download vs ExistingPackages)
119+ log .WithField ("errorCount" , len (errs )).Debug ("Some packages had errors during processing" )
117120 return fmt .Errorf ("multiple errors occurred: %v" , errs )
118121 }
119122
@@ -326,19 +329,42 @@ func (s *S3Cache) Download(ctx context.Context, dst cache.LocalCache, pkgs []cac
326329
327330// Upload implements RemoteCache
328331func (s * S3Cache ) Upload (ctx context.Context , src cache.LocalCache , pkgs []cache.Package ) error {
329- return s .processPackages (ctx , pkgs , func (ctx context.Context , p cache.Package ) error {
332+ var uploadErrors []error
333+
334+ err := s .processPackages (ctx , pkgs , func (ctx context.Context , p cache.Package ) error {
330335 localPath , exists := src .Location (p )
331336 if ! exists {
332- return fmt .Errorf ("package %s not found in local cache" , p .FullName ())
337+ log .WithField ("package" , p .FullName ()).Warn ("package not found in local cache - skipping upload" )
338+ return nil // Skip but don't fail everything
333339 }
334340
335341 key := filepath .Base (localPath )
336342 if err := s .storage .UploadObject (ctx , key , localPath ); err != nil {
337- return fmt .Errorf ("failed to upload package %s: %w" , p .FullName (), err )
343+ log .WithError (err ).WithFields (log.Fields {
344+ "package" : p .FullName (),
345+ "key" : key ,
346+ }).Warn ("failed to upload package to remote cache - continuing" )
347+ uploadErrors = append (uploadErrors , fmt .Errorf ("package %s: %w" , p .FullName (), err ))
348+ return nil // Don't fail the entire operation
338349 }
339350
351+ log .WithFields (log.Fields {
352+ "package" : p .FullName (),
353+ "key" : key ,
354+ }).Debug ("successfully uploaded package to remote cache" )
340355 return nil
341356 })
357+
358+ if err != nil {
359+ log .WithError (err ).Warn ("errors occurred during upload to remote cache - continuing" )
360+ // Don't return the error to allow the build to continue
361+ }
362+
363+ if len (uploadErrors ) > 0 {
364+ log .WithField ("errorCount" , len (uploadErrors )).Warn ("some packages failed to upload to remote cache - continuing with build" )
365+ }
366+
367+ return nil // Always return nil to allow the build to continue
342368}
343369
344370// s3ClientAPI is a subset of the S3 client interface we need
@@ -475,6 +501,7 @@ func (s *S3Storage) GetObject(ctx context.Context, key string, dest string) (int
475501func (s * S3Storage ) UploadObject (ctx context.Context , key string , src string ) error {
476502 file , err := os .Open (src )
477503 if err != nil {
504+ log .WithError (err ).WithField ("key" , key ).Warn ("failed to open source file for upload" )
478505 return fmt .Errorf ("failed to open source file: %w" , err )
479506 }
480507 defer file .Close ()
@@ -492,10 +519,20 @@ func (s *S3Storage) UploadObject(ctx context.Context, key string, src string) er
492519 _ , err = uploader .Upload (ctx , input )
493520 if err != nil {
494521 var apiErr smithy.APIError
495- if errors .As (err , & apiErr ) && apiErr .ErrorCode () == "Forbidden" {
496- log .WithError (err ).Warnf ("permission denied while uploading object %s to S3 - continuing" , key )
497- return nil
522+ if errors .As (err , & apiErr ) {
523+ if apiErr .ErrorCode () == "Forbidden" {
524+ log .WithError (err ).Warnf ("permission denied while uploading object %s to S3 - continuing" , key )
525+ return nil
526+ }
527+ // Handle other API errors as warnings too
528+ log .WithError (err ).WithFields (log.Fields {
529+ "key" : key ,
530+ "errorCode" : apiErr .ErrorCode (),
531+ }).Warn ("S3 API error while uploading object - continuing" )
532+ return fmt .Errorf ("S3 API error: %w" , err )
498533 }
534+ // Handle non-API errors
535+ log .WithError (err ).WithField ("key" , key ).Warn ("failed to upload object - continuing" )
499536 return fmt .Errorf ("failed to upload object: %w" , err )
500537 }
501538
0 commit comments