{"record":{"id":"ae4f91d574c56922","repo":"GoogleContainerTools/skaffold","slug":"failed-to-copy-object-to-file-v","errorCode":null,"errorMessage":"failed to copy object to file: %v","messagePattern":"failed to copy object to file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/gcs/client/native.go","lineNumber":337,"sourceCode":"\t}\n\treturn matches, nil\n}\n\nfunc (nb nativeBucketHandler) DownloadObject(ctx context.Context, localPath, uri string) error {\n\treader, err := nb.bucket.Object(uri).NewReader(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to read object: %v\", err)\n\t}\n\tdefer reader.Close()\n\n\tfile, err := os.Create(localPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create file: %v\", err)\n\t}\n\tdefer file.Close()\n\n\tif _, err := io.Copy(file, reader); err != nil {\n\t\treturn fmt.Errorf(\"failed to copy object to file: %v\", err)\n\t}\n\n\treturn nil\n}\n\nfunc (nb nativeBucketHandler) UploadObject(ctx context.Context, objName string, content *os.File) error {\n\twc := nb.bucket.Object(objName).NewWriter(ctx)\n\tif _, err := io.Copy(wc, content); err != nil {\n\t\treturn fmt.Errorf(\"error copying file to GCS: %w\", err)\n\t}\n\tif err := wc.Close(); err != nil {\n\t\treturn fmt.Errorf(\"error closing GCS writer: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc (nb nativeBucketHandler) Close() {\n\tnb.storageClient.Close()","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/gcs/client/native.go#L319-L355","documentation":"DownloadObject wraps io.Copy failures while streaming the GCS object into the local file. It means the transfer was interrupted: a network error or timeout reading from GCS, or a local write error (disk full). The partial local file may be left behind.","triggerScenarios":"During a DownloadObject/DownloadRecursive transfer, the connection to storage.googleapis.com drops or the context is cancelled mid-stream, or the destination disk fills while writing a large object.","commonSituations":"Large multi-GB artifacts downloaded on flaky CI networks; context deadline exceeded on slow links; laptop suspending mid-download; ENOSPC when downloading a big dataset to a small volume.","solutions":["Retry the download; on success a fresh call rewrites the file (consider deleting the partial file first)","Increase the context timeout or remove premature cancellation for large transfers","Free disk space or verify capacity before downloading large objects","Check network/proxy stability; rerun on a reliable connection"],"exampleFix":"// before\nctx := context.Background()\n// interrupted downloads leave partial files\n// after\nctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)\ndefer cancel()\nif err := bucket.DownloadObject(ctx, localPath, uri); err != nil {\n    os.Remove(localPath) // clean partial file\n    /* retry or handle */\n}","handlingStrategy":"retry","validationCode":"func hasDiskSpace(dir string, minBytes uint64) error {\n\tvar st syscall.Statfs_t\n\tif err := syscall.Statfs(dir, &st); err != nil { return err }\n\tif uint64(st.Bavail)*uint64(st.Bsize) < minBytes {\n\t\treturn fmt.Errorf(\"insufficient disk space in %s\", dir)\n\t}\n\treturn nil\n}\n// check space before large downloads; transfer errors themselves warrant retry","typeGuard":null,"tryCatchPattern":"err := n.DownloadRecursive(ctx, src, dst)\nif err != nil && strings.Contains(err.Error(), \"failed to copy object to file\") {\n\t// clean partial files, then retry\n\tos.RemoveAll(dst)\n\treturn retryBackoff(3, 2*time.Second, func() error {\n\t\treturn n.DownloadRecursive(ctx, src, dst)\n\t})\n}","preventionTips":["Use generous context timeouts for large transfers","Delete partial files after failed downloads","Verify disk capacity against expected download size","Prefer stable networks; surface retry progress in CI logs"],"tags":["gcs","network","io","download"],"backgroundTag":"download-interrupted","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}