{"record":{"id":"f3a8704a0e5548dd","repo":"GoogleContainerTools/skaffold","slug":"uploading-sources-to-google-storage-w","errorCode":null,"errorMessage":"uploading sources to google storage: %w","messagePattern":"uploading sources to google storage: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/sources/upload.go","lineNumber":34,"sourceCode":"\npackage sources\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\tcstorage \"cloud.google.com/go/storage\"\n\n\t\"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/schema/latest\"\n\t\"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/util\"\n)\n\n// UploadToGCS uploads the artifact's sources to a GCS bucket.\nfunc UploadToGCS(ctx context.Context, c *cstorage.Client, a *latest.Artifact, bucket, objectName string, dependencies []string) error {\n\tw := c.Bucket(bucket).Object(objectName).NewWriter(ctx)\n\n\tif err := util.CreateTarGz(ctx, w, a.Workspace, dependencies); err != nil {\n\t\treturn fmt.Errorf(\"uploading sources to google storage: %w\", err)\n\t}\n\n\treturn w.Close()\n}\n","sourceCodeStart":16,"sourceCodeEnd":39,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/sources/upload.go#L16-L39","documentation":"`UploadToGCS` wraps failures from `util.CreateTarGz`, which streams a tar.gz of the artifact's source dependencies directly into a GCS object writer. The error means the sources could not be archived and uploaded to the given GCS bucket/object — either the local archive creation failed (missing files, IO errors) or the streaming write to GCS failed mid-upload.","triggerScenarios":"Calling `UploadToGCS(ctx, client, artifact, bucket, objectName, dependencies)` where `dependencies` reference files that don't exist under `a.Workspace`, the workspace is unreadable, the GCS credentials are missing/invalid, the bucket doesn't exist or is not writable, or the network drops during upload.","commonSituations":"Cloud build workflows where the GCS staging bucket name is misspelled or the service account lacks storage.objects.create; source files deleted after dependency computation; 403 from GCS due to no storage scope on the VM; flaky network interrupting the multipart upload.","solutions":["Verify GCS credentials and that the service account has Object Creator (roles/storage.objectCreator) on the bucket.","Confirm the bucket exists and the objectName/bucket spelling is correct.","Ensure all files listed in `dependencies` exist inside `a.Workspace` and are readable.","Check network/proxy connectivity to storage.googleapis.com and retry transient failures."],"exampleFix":"// before\nc := client.NewGCSClient(ctx) // no credentials/scopes\nerr := sources.UploadToGCS(ctx, c, artifact, \"my-bucket\", \"src.tgz\", deps)\n// after\n// grant storage.objectCreator to the SA and authenticate:\n// gcloud auth application-default login  (or attach storage scope)\nerr := sources.UploadToGCS(ctx, c, artifact, \"my-bucket\", \"src.tgz\", verifiedDeps)","handlingStrategy":"validation","validationCode":"for _, dep := range dependencies {\n  if _, err := os.Stat(filepath.Join(a.Workspace, dep)); err != nil {\n    return fmt.Errorf(\"missing dependency %q before GCS upload: %w\", dep, err)\n  }\n}\nif err := c.Bucket(bucket).Objects(ctx, nil); err != nil { // probe bucket access\n  return fmt.Errorf(\"bucket %q not accessible: %w\", bucket, err)\n}","typeGuard":null,"tryCatchPattern":"err := sources.UploadToGCS(ctx, client, artifact, bucket, obj, deps)\nif err != nil {\n  if strings.Contains(err.Error(), \"uploading sources to google storage\") {\n    log.Printf(\"GCS upload failed: %v; check credentials/bucket and retry\", err)\n  }\n  return err\n}","preventionTips":["Grant the service account roles/storage.objectCreator on the staging bucket.","Run `gcloud auth application-default login` or attach storage scopes in CI.","Validate all dependency paths exist under the workspace before uploading.","Confirm network/proxy access to storage.googleapis.com from your environment."],"tags":["gcs","upload","network","cloud-build","go"],"backgroundTag":"gcs-upload-failed","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"}