{"record":{"id":"606b650ec8db8f2b","repo":"kubernetes/kops","slug":"error-creating-temp-file-in-q-v","errorCode":null,"errorMessage":"error creating temp file in %q: %v","messagePattern":"error creating temp file in %q: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/pkg/vfs/fs.go","lineNumber":63,"sourceCode":"}\n\nfunc (p *FSPath) Join(relativePath ...string) Path {\n\targs := []string{p.location}\n\targs = append(args, relativePath...)\n\tjoined := filepath.Join(args...)\n\treturn &FSPath{location: joined}\n}\n\nfunc (p *FSPath) WriteFile(ctx context.Context, data io.ReadSeeker, acl ACL) error {\n\tdir := filepath.Dir(p.location)\n\terr := os.MkdirAll(dir, 0o755)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error creating directories %q: %v\", dir, err)\n\t}\n\n\tf, err := os.CreateTemp(dir, \"tmp\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error creating temp file in %q: %v\", dir, err)\n\t}\n\n\t// Note from here on in we have to close f and delete or rename the temp file\n\ttempfile := f.Name()\n\n\t_, err = io.Copy(f, data)\n\n\tif closeErr := f.Close(); err == nil {\n\t\terr = closeErr\n\t}\n\n\tif err == nil {\n\t\terr = os.Rename(tempfile, p.location)\n\t\tif err != nil {\n\t\t\terr = fmt.Errorf(\"error during file write of %q: rename failed: %v\", p.location, err)\n\t\t}\n\t}\n","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/util/pkg/vfs/fs.go#L45-L81","documentation":"After ensuring the directory exists, WriteFile creates a temporary file in that directory with os.CreateTemp to stage the write. This error wraps CreateTemp failures such as permission denied on the (now-existing) directory, disk full, or the directory being removed between the MkdirAll and CreateTemp calls.","triggerScenarios":"Calling CreateFile/WriteFile where os.CreateTemp(dir, \"tmp\") fails: directory not writable despite existing, no inodes/space left, or dir vanished between MkdirAll and CreateTemp.","commonSituations":"Directory owned by another user (created earlier as root), full disk or inode exhaustion on the node, or TMPDIR-style restrictions where the fs mount is noexec/nodev with odd permissions.","solutions":["Grant write permission on the target directory for the running user.","Free disk space / check inode usage (df -h, df -i).","Re-check that the directory still exists (no concurrent cleanup job deleting it).","Retry the write after fixing the transient condition."],"exampleFix":"// before\nf, err := os.CreateTemp(dir, \"tmp\") // dir owned by root\n// after\nsudo chown -R $(whoami) /path/to/dir\nf, err := os.CreateTemp(dir, \"tmp\")","handlingStrategy":"try-catch","validationCode":"if err := unix.Access(dir, unix.W_OK); err != nil {\n    return fmt.Errorf(\"directory %s is not writable\", dir)\n}\nif err := checkDiskSpace(dir); err != nil {\n    return err\n}","typeGuard":null,"tryCatchPattern":"if err := p.WriteFile(ctx, data, acl); err != nil && strings.Contains(err.Error(), \"error creating temp file\") {\n    // usually permissions or ENOSPC; surface a targeted hint\n    return fmt.Errorf(\"check write permission and free space in %s: %w\", dir, err)\n}","preventionTips":["Monitor disk space and inodes on nodes that write local VFS state.","Ensure the directory owner matches the service user.","Avoid concurrent jobs that might delete the directory mid-write."],"tags":["filesystem","vfs","permissions"],"backgroundTag":"temp-file-write-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}