Skip to content

Commit 0a185e9

Browse files
committed
Do not return an error uploading to remote cache
1 parent f550141 commit 0a185e9

File tree

2 files changed

+43
-16
lines changed

2 files changed

+43
-16
lines changed

pkg/leeway/cache/remote/s3.go

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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
328331
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 {
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
@@ -473,6 +499,7 @@ func (s *S3Storage) GetObject(ctx context.Context, key string, dest string) (int
473499
func (s *S3Storage) UploadObject(ctx context.Context, key string, src string) error {
474500
file, err := os.Open(src)
475501
if err != nil {
502+
log.WithError(err).WithField("key", key).Warn("failed to open source file for upload")
476503
return fmt.Errorf("failed to open source file: %w", err)
477504
}
478505
defer file.Close()
@@ -490,10 +517,20 @@ func (s *S3Storage) UploadObject(ctx context.Context, key string, src string) er
490517
_, err = uploader.Upload(ctx, input)
491518
if err != nil {
492519
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)
496531
}
532+
// Handle non-API errors
533+
log.WithError(err).WithField("key", key).Warn("failed to upload object - continuing")
497534
return fmt.Errorf("failed to upload object: %w", err)
498535
}
499536

pkg/leeway/cache/remote/s3_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -368,16 +368,6 @@ func TestS3Cache_Upload(t *testing.T) {
368368
},
369369
},
370370
},
371-
{
372-
name: "package not in local cache",
373-
packages: []cache.Package{
374-
&mockPackage{version: "v1"},
375-
},
376-
localCache: &mockLocalCache{
377-
locations: map[string]string{},
378-
},
379-
expectError: true,
380-
},
381371
{
382372
name: "403 forbidden error should not fail",
383373
packages: []cache.Package{

0 commit comments

Comments
 (0)