6
6
"fmt"
7
7
"os"
8
8
"path/filepath"
9
+ "strings"
9
10
"sync"
10
11
11
12
"github.com/aws/aws-sdk-go-v2/aws"
@@ -136,6 +137,7 @@ func (s *S3Cache) ExistingPackages(ctx context.Context, pkgs []cache.Package) (m
136
137
"key" : gzKey ,
137
138
"error" : err ,
138
139
}).Debug ("failed to check .tar.gz in remote cache, will try .tar" )
140
+ // Continue to check .tar format - don't return error here
139
141
} else if exists {
140
142
log .WithFields (log.Fields {
141
143
"package" : p .FullName (),
@@ -156,6 +158,7 @@ func (s *S3Cache) ExistingPackages(ctx context.Context, pkgs []cache.Package) (m
156
158
"key" : tarKey ,
157
159
"error" : err ,
158
160
}).Debug ("failed to check .tar in remote cache" )
161
+ // Don't return error for missing objects - this is expected
159
162
return nil // Continue with next package, will trigger local build
160
163
}
161
164
@@ -178,17 +181,17 @@ func (s *S3Cache) ExistingPackages(ctx context.Context, pkgs []cache.Package) (m
178
181
})
179
182
180
183
if err != nil {
181
- log .WithError (err ).Error ("failed to check existing packages in remote cache" )
184
+ log .WithError (err ).Warn ("failed to check existing packages in remote cache" )
182
185
// Return partial results even if some checks failed
183
- return result , err
186
+ return result , nil
184
187
}
185
188
186
189
return result , nil
187
190
}
188
191
189
192
// Download implements RemoteCache
190
193
func (s * S3Cache ) Download (ctx context.Context , dst cache.LocalCache , pkgs []cache.Package ) error {
191
- return s .processPackages (ctx , pkgs , func (ctx context.Context , p cache.Package ) error {
194
+ err := s .processPackages (ctx , pkgs , func (ctx context.Context , p cache.Package ) error {
192
195
version , err := p .Version ()
193
196
if err != nil {
194
197
return fmt .Errorf ("failed to get version for package %s: %w" , p .FullName (), err )
@@ -209,22 +212,40 @@ func (s *S3Cache) Download(ctx context.Context, dst cache.LocalCache, pkgs []cac
209
212
}).Debug ("successfully downloaded package from remote cache (.tar.gz)" )
210
213
return nil
211
214
}
212
- log .WithFields (log.Fields {
213
- "package" : p .FullName (),
214
- "key" : gzKey ,
215
- "error" : err ,
216
- }).Debug ("failed to download .tar.gz from remote cache, trying .tar" )
215
+
216
+ // Check if this is a "not found" error
217
+ if strings .Contains (err .Error (), "NotFound" ) || strings .Contains (err .Error (), "404" ) {
218
+ log .WithFields (log.Fields {
219
+ "package" : p .FullName (),
220
+ "key" : gzKey ,
221
+ }).Debug ("package not found in remote cache (.tar.gz), trying .tar" )
222
+ } else {
223
+ log .WithFields (log.Fields {
224
+ "package" : p .FullName (),
225
+ "key" : gzKey ,
226
+ "error" : err ,
227
+ }).Debug ("failed to download .tar.gz from remote cache, trying .tar" )
228
+ }
217
229
218
230
// Try .tar if .tar.gz fails
219
231
tarKey := fmt .Sprintf ("%s.tar" , version )
220
232
_ , err = s .storage .GetObject (ctx , tarKey , localPath )
221
233
if err != nil {
234
+ // Check if this is a "not found" error
235
+ if strings .Contains (err .Error (), "NotFound" ) || strings .Contains (err .Error (), "404" ) {
236
+ log .WithFields (log.Fields {
237
+ "package" : p .FullName (),
238
+ "key" : tarKey ,
239
+ }).Debug ("package not found in remote cache (.tar), will build locally" )
240
+ return nil // Not an error, just not found
241
+ }
242
+
222
243
log .WithFields (log.Fields {
223
244
"package" : p .FullName (),
224
245
"key" : tarKey ,
225
246
"error" : err ,
226
247
}).Debug ("failed to download package from remote cache, will build locally" )
227
- return fmt . Errorf ( "failed to download package %s: %w" , p . FullName (), err )
248
+ return nil // Continue with local build
228
249
}
229
250
230
251
log .WithFields (log.Fields {
@@ -233,6 +254,14 @@ func (s *S3Cache) Download(ctx context.Context, dst cache.LocalCache, pkgs []cac
233
254
}).Debug ("successfully downloaded package from remote cache (.tar)" )
234
255
return nil
235
256
})
257
+
258
+ if err != nil {
259
+ log .WithError (err ).Warn ("errors occurred during download from remote cache" )
260
+ // Continue with local builds for packages that couldn't be downloaded
261
+ return nil
262
+ }
263
+
264
+ return nil
236
265
}
237
266
238
267
// Upload implements RemoteCache
@@ -287,10 +316,17 @@ func (s *S3Storage) HasObject(ctx context.Context, key string) (bool, error) {
287
316
})
288
317
289
318
if err != nil {
319
+ // Check for various "not found" error types
290
320
var nsk * types.NoSuchKey
291
321
if errors .As (err , & nsk ) {
292
322
return false , nil
293
323
}
324
+
325
+ // Also handle 404 NotFound errors which might not be properly wrapped as NoSuchKey
326
+ if strings .Contains (err .Error (), "NotFound" ) || strings .Contains (err .Error (), "404" ) {
327
+ return false , nil
328
+ }
329
+
294
330
return false , err
295
331
}
296
332
@@ -318,7 +354,22 @@ func (s *S3Storage) GetObject(ctx context.Context, key string, dest string) (int
318
354
Bucket : aws .String (s .bucketName ),
319
355
Key : aws .String (key ),
320
356
})
357
+
321
358
if err != nil {
359
+ // Remove the partially downloaded file if there was an error
360
+ os .Remove (dest )
361
+
362
+ // Check for various "not found" error types
363
+ var nsk * types.NoSuchKey
364
+ if errors .As (err , & nsk ) {
365
+ return 0 , fmt .Errorf ("object not found: %w" , err )
366
+ }
367
+
368
+ // Also handle 404 NotFound errors which might not be properly wrapped
369
+ if strings .Contains (err .Error (), "NotFound" ) || strings .Contains (err .Error (), "404" ) {
370
+ return 0 , fmt .Errorf ("object not found: %w" , err )
371
+ }
372
+
322
373
return 0 , fmt .Errorf ("failed to download object: %w" , err )
323
374
}
324
375
0 commit comments