{"record":{"id":"51987ba2f58a9046","repo":"GoogleContainerTools/skaffold","slug":"copy-file-s-with-s-failed-w","errorCode":null,"errorMessage":"copy file(s) with %s failed: %w","messagePattern":"copy file\\(s\\) with (.+?) failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/gcs/gsutil.go","lineNumber":62,"sourceCode":"\ntype gsutil struct{}\n\n// NewGsutil returns a gsutil client.\nfunc NewGsutil() Gsutil {\n\treturn &gsutil{}\n}\n\n// Copy calls `gcloud storage cp [--recursive] <source_url> <destination_url>\nfunc (g *gsutil) Copy(ctx context.Context, src, dst string, recursive bool) error {\n\targs := []string{\"storage\", \"cp\"}\n\tif recursive {\n\t\targs = append(args, \"--recursive\")\n\t}\n\targs = append(args, src, dst)\n\tcmd := exec.CommandContext(ctx, GsutilExec, args...)\n\tout, err := util.RunCmdOut(ctx, cmd)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"copy file(s) with %s failed: %w\", GsutilExec, err)\n\t}\n\tlog.Entry(ctx).Info(out)\n\treturn nil\n}\n\n// GetGCSClient returns a GCS client that uses Client libraries.\nvar GetGCSClient = func() gscClient {\n\treturn &client.Native{}\n}\n\ntype gscClient interface {\n\t// Downloads the content that match the given src uri and subfolders.\n\tDownloadRecursive(ctx context.Context, src, dst string) error\n}\n\n// SyncObjects syncs the target Google Cloud Storage objects with skaffold's local cache and returns the local path to the objects.\nfunc SyncObjects(ctx context.Context, g latest.GoogleCloudStorageInfo, opts config.SkaffoldOptions) (string, error) {\n\tremoteCacheDir, err := config.GetRemoteCacheDir(opts)","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/gcs/gsutil.go#L44-L80","documentation":"Copy runs the external `gsutil` binary (GsutilExec) with `cp` arguments to copy files to/from GCS and wraps any failure from util.RunCmdOut. Because it shells out to gsutil, the error usually reflects gsutil's own failure — missing binary, bad arguments, authentication problems, or the source/destination not existing. The wrapped error carries gsutil's stderr output for diagnosis.","triggerScenarios":"Calling gcs.Copy when the gsutil executable is not on PATH, the source path or destination URL is wrong or nonexistent, credentials are invalid (run `gcloud auth login`), or gsutil exits nonzero for network/API reasons.","commonSituations":"gsutil not installed (Cloud SDK missing) on CI machines; GCS URLs mistyped (gs:// prefix forgotten); service account not activated (`gcloud auth activate-service-account` skipped); copying a nonexistent local file with --recursive misconfigured.","solutions":["Verify gsutil is installed and on PATH: `which gsutil` or install Google Cloud SDK","Run the same gsutil cp command manually to see the raw error","Re-authenticate: `gcloud auth login` or `gcloud auth activate-service-account --key-file=...`","Check that the src path and gs:// dst exist and are correctly formatted","Confirm network/proxy access to storage.googleapis.com from the environment"],"exampleFix":"// before\nerr := gcs.Copy(ctx, opts, src, dst)\n// after\nif _, err := exec.LookPath(gcs.GsutilExec); err != nil {\n\tlog.Fatalf(\"gsutil not found; install Google Cloud SDK: %v\", err)\n}\nerr := gcs.Copy(ctx, opts, src, dst)","handlingStrategy":"try-catch","validationCode":"if _, err := exec.LookPath(\"gsutil\"); err != nil {\n\treturn fmt.Errorf(\"gsutil not installed: %w\", err)\n}\nif !strings.HasPrefix(dst, \"gs://\") {\n\treturn fmt.Errorf(\"destination must be a gs:// URL: %q\", dst)\n}\nif _, err := os.Stat(src); err != nil {\n\treturn fmt.Errorf(\"source missing: %w\", err)\n}","typeGuard":"func isGsutilNotFoundError(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"CommandException\") && strings.Contains(err.Error(), \"No such file or directory\")\n}","tryCatchPattern":"if err := gcs.Copy(ctx, opts, src, dst); err != nil {\n\tif errors.Is(err, exec.ErrNotFound) || strings.Contains(err.Error(), \"executable file not found\") {\n\t\tlog.Fatal(\"install Google Cloud SDK (gsutil) first\")\n\t}\n\treturn fmt.Errorf(\"gcs copy failed: %w\", err)\n}","preventionTips":["Install Google Cloud SDK in all environments (CI images) where skaffold uses the gsutil path","Always use gs:// URLs, not https URLs, for GCS arguments","Run `gcloud auth login` / activate-service-account before invoking Copy","Prefer the native client handler over gsutil where possible to avoid external-binary failures","Manually run the gsutil command to confirm credentials and paths work before automation"],"tags":["gcs","gsutil","exec","go","external-tool"],"backgroundTag":"gsutil-command-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"}