{"record":{"id":"19dcba03cde8f54d","repo":"GoogleContainerTools/skaffold","slug":"failed-to-create-file-v","errorCode":null,"errorMessage":"failed to create file: %v","messagePattern":"failed to create file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/gcs/client/native.go","lineNumber":332,"sourceCode":"\t\t}\n\n\t\tif attrs.Name != \"\" {\n\t\t\tmatches = append(matches, attrs.Name)\n\t\t}\n\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}","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/gcs/client/native.go#L314-L350","documentation":"DownloadObject wraps os.Create failures for the local destination file after the GCS reader was opened successfully. It means the local file could not be created — destination directory missing, no write permission, dst is a directory, or disk is full. The object content is never written in this case.","triggerScenarios":"filepath.Join(dst, localPath) in DownloadRecursive points somewhere unwritable: parent dir not created (e.g. os.Stat falsely reported it exists), dst path is an existing directory with the object's name, or the filesystem is read-only/full.","commonSituations":"Downloading into a container volume mounted read-only; an object named like an existing local directory (e.g. object 'a' where ./a/ is a dir); ENOSPC on a small CI disk; running as non-root against root-owned paths.","solutions":["Check the wrapped error for 'permission denied' / 'is a directory' / 'no space left' and fix accordingly","Ensure the destination directory exists and is writable (MkdirAll with a verified writable dst)","Free disk space or point dst to a larger volume","Remove/rename any local directory that collides with the target file name"],"exampleFix":"// before\nerr := n.DownloadRecursive(ctx, \"gs://bucket/data/**\", \"/mnt/ro-volume/out\") // read-only\n// after\ndst := \"/tmp/gcs-out\" // writable location\nif err := os.MkdirAll(dst, os.ModePerm); err != nil { /* handle */ }\nif err := n.DownloadRecursive(ctx, \"gs://bucket/data/**\", dst); err != nil { /* handle */ }","handlingStrategy":"validation","validationCode":"func ensureDownloadTarget(dst string) error {\n\tif fi, err := os.Stat(dst); err == nil {\n\t\tif fi.IsDir() {\n\t\t\treturn fmt.Errorf(\"%s is a directory, expected file target\", dst)\n\t\t}\n\t\tif fi.Mode().Perm()&0o200 == 0 {\n\t\t\treturn fmt.Errorf(\"%s is not writable\", dst)\n\t\t}\n\t}\n\tdir := filepath.Dir(dst)\n\tif err := os.MkdirAll(dir, os.ModePerm); err != nil {\n\t\treturn fmt.Errorf(\"cannot create %s: %w\", dir, err)\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-create the destination directory tree and probe writability","Check free disk space before large downloads","Avoid destination paths that collide with existing directories","Never download into read-only mounts"],"tags":["filesystem","gcs","permissions","download"],"backgroundTag":"file-create-permission-denied","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"}