@@ -114,6 +114,9 @@ func (s *S3Cache) processPackages(ctx context.Context, pkgs []cache.Package, fn
114
114
}
115
115
116
116
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" )
117
120
return fmt .Errorf ("multiple errors occurred: %v" , errs )
118
121
}
119
122
@@ -326,19 +329,42 @@ func (s *S3Cache) Download(ctx context.Context, dst cache.LocalCache, pkgs []cac
326
329
327
330
// Upload implements RemoteCache
328
331
func (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 {
330
335
localPath , exists := src .Location (p )
331
336
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
333
339
}
334
340
335
341
key := filepath .Base (localPath )
336
342
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
338
349
}
339
350
351
+ log .WithFields (log.Fields {
352
+ "package" : p .FullName (),
353
+ "key" : key ,
354
+ }).Debug ("successfully uploaded package to remote cache" )
340
355
return nil
341
356
})
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
342
368
}
343
369
344
370
// 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
475
501
func (s * S3Storage ) UploadObject (ctx context.Context , key string , src string ) error {
476
502
file , err := os .Open (src )
477
503
if err != nil {
504
+ log .WithError (err ).WithField ("key" , key ).Warn ("failed to open source file for upload" )
478
505
return fmt .Errorf ("failed to open source file: %w" , err )
479
506
}
480
507
defer file .Close ()
@@ -492,10 +519,20 @@ func (s *S3Storage) UploadObject(ctx context.Context, key string, src string) er
492
519
_ , err = uploader .Upload (ctx , input )
493
520
if err != nil {
494
521
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 )
498
533
}
534
+ // Handle non-API errors
535
+ log .WithError (err ).WithField ("key" , key ).Warn ("failed to upload object - continuing" )
499
536
return fmt .Errorf ("failed to upload object: %w" , err )
500
537
}
501
538
0 commit comments