Skip to content

Commit 03f977c

Browse files
authored
Return error when the write fails (#1604)
1 parent 299c403 commit 03f977c

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

packages/orchestrator/internal/server/sandboxes.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,8 @@ func (s *Server) Pause(ctx context.Context, in *orchestrator.SandboxPauseRequest
442442

443443
return
444444
}
445+
446+
logger.L().Info(ctx, "Sandbox snapshot uploaded successfully", logger.WithSandboxID(in.GetSandboxId()))
445447
}(context.WithoutCancel(ctx))
446448

447449
teamID, buildId, eventData := s.prepareSandboxEventData(ctx, sbx)

packages/shared/pkg/storage/storage_google.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,19 +244,26 @@ func (g *GCPBucketStorageObjectProvider) ReadAt(ctx context.Context, buff []byte
244244
return n, nil
245245
}
246246

247-
func (g *GCPBucketStorageObjectProvider) Write(ctx context.Context, data []byte) (int, error) {
247+
func (g *GCPBucketStorageObjectProvider) Write(ctx context.Context, data []byte) (n int, e error) {
248248
timer := googleWriteTimerFactory.Begin()
249+
defer func() {
250+
if e == nil {
251+
timer.End(ctx, int64(n))
252+
}
253+
}()
249254

250255
w := g.handle.NewWriter(ctx)
251-
defer w.Close()
256+
defer func() {
257+
if err := w.Close(); err != nil {
258+
e = errors.Join(e, fmt.Errorf("failed to write to %q: %w", g.path, err))
259+
}
260+
}()
252261

253262
n, err := w.Write(data)
254263
if err != nil && !errors.Is(err, io.EOF) {
255264
return n, fmt.Errorf("failed to write to %q: %w", g.path, err)
256265
}
257266

258-
timer.End(ctx, int64(n))
259-
260267
return n, nil
261268
}
262269

0 commit comments

Comments
 (0)