@@ -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
@@ -473,6 +499,7 @@ func (s *S3Storage) GetObject(ctx context.Context, key string, dest string) (int
473
499
func (s * S3Storage ) UploadObject (ctx context.Context , key string , src string ) error {
474
500
file , err := os .Open (src )
475
501
if err != nil {
502
+ log .WithError (err ).WithField ("key" , key ).Warn ("failed to open source file for upload" )
476
503
return fmt .Errorf ("failed to open source file: %w" , err )
477
504
}
478
505
defer file .Close ()
@@ -490,10 +517,20 @@ func (s *S3Storage) UploadObject(ctx context.Context, key string, src string) er
490
517
_ , err = uploader .Upload (ctx , input )
491
518
if err != nil {
492
519
var apiErr smithy.APIError
493
- if errors .As (err , & apiErr ) && apiErr .ErrorCode () == "Forbidden" {
494
- log .WithError (err ).Warnf ("permission denied while uploading object %s to S3 - continuing" , key )
495
- return nil
520
+ if errors .As (err , & apiErr ) {
521
+ if apiErr .ErrorCode () == "Forbidden" {
522
+ log .WithError (err ).Warnf ("permission denied while uploading object %s to S3 - continuing" , key )
523
+ return nil
524
+ }
525
+ // Handle other API errors as warnings too
526
+ log .WithError (err ).WithFields (log.Fields {
527
+ "key" : key ,
528
+ "errorCode" : apiErr .ErrorCode (),
529
+ }).Warn ("S3 API error while uploading object - continuing" )
530
+ return fmt .Errorf ("S3 API error: %w" , err )
496
531
}
532
+ // Handle non-API errors
533
+ log .WithError (err ).WithField ("key" , key ).Warn ("failed to upload object - continuing" )
497
534
return fmt .Errorf ("failed to upload object: %w" , err )
498
535
}
499
536
0 commit comments