{"record":{"id":"24af529affaf92e7","repo":"kubernetes/kops","slug":"error-creating-directories-for-destination-file-q","errorCode":null,"errorMessage":"error creating directories for destination file %q: %v","messagePattern":"error creating directories for destination file %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/files.go","lineNumber":35,"sourceCode":"package fi\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"os\"\n\t\"path\"\n\t\"path/filepath\"\n\t\"strconv\"\n\n\t\"k8s.io/klog/v2\"\n\t\"k8s.io/kops/util/pkg/hashing\"\n)\n\n// WriteFile writes a file to the specified path, setting the mode, owner & group.\nfunc WriteFile(destPath string, contents Resource, fileMode os.FileMode, dirMode os.FileMode, owner string, group string) error {\n\terr := os.MkdirAll(path.Dir(destPath), dirMode)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error creating directories for destination file %q: %v\", destPath, err)\n\t}\n\n\terr = writeFileContents(destPath, contents, fileMode)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t_, err = EnsureFileMode(destPath, fileMode)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t_, err = EnsureFileOwner(destPath, owner, group)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn nil","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/files.go#L17-L53","documentation":"Thrown by fi.WriteFile when os.MkdirAll fails to create the parent directory tree for the destination path. Common causes: permission denied on an existing parent directory, a path component that is a file rather than a directory, or read-only filesystem at the destination.","triggerScenarios":"Thrown at upup/pkg/fi/files.go:35 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check permissions on the parent directories of the destination path and grant write access","Remove a regular file that occupies a needed directory component","Verify the destination filesystem is writable (not read-only or full)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}