{"record":{"id":"5404499a891eac7c","repo":"hashicorp/nomad","slug":"failed-to-create-parent-directories-of-q-w","errorCode":null,"errorMessage":"failed to create parent directories of %q: %w","messagePattern":"failed to create parent directories of %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/operator_debug.go","lineNumber":1405,"sourceCode":"\tc.writeBody(dir, \"vault-sys-health.json\", resp, err)\n\n\treturn nil\n}\n\n// writeBytes writes a file to the archive, recording it in the manifest\nfunc (c *OperatorDebugCommand) writeBytes(dir, file string, data []byte) error {\n\t// Replace invalid characters in filename\n\tfilename := helper.CleanFilename(file, \"_\")\n\n\trelativePath := filepath.Join(dir, filename)\n\tc.manifest = append(c.manifest, relativePath)\n\tdirPath := filepath.Join(c.collectDir, dir)\n\tfilePath := filepath.Join(dirPath, filename)\n\n\t// Ensure parent directories exist\n\terr := escapingfs.EnsurePath(dirPath, true)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create parent directories of %q: %w\", dirPath, err)\n\t}\n\n\t// Ensure filename doesn't escape the sandbox of the capture directory\n\tescapes := escapingfs.PathEscapesSandbox(c.collectDir, filePath)\n\tif escapes {\n\t\treturn fmt.Errorf(\"file path %q escapes capture directory %q\", filePath, c.collectDir)\n\t}\n\n\t// Create the file\n\tfh, err := os.Create(filePath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create file %q, err: %w\", filePath, err)\n\t}\n\tdefer fh.Close()\n\n\t_, err = fh.Write(data)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Failed to write data to file %q, err: %w\", filePath, err)","sourceCodeStart":1387,"sourceCodeEnd":1423,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/operator_debug.go#L1387-L1423","documentation":"Thrown by `writeBytes` in the operator debug collector when `escapingfs.EnsurePath` fails to create the parent directory tree for an output file inside the capture directory. Nomad wraps the filesystem error (permission denied, not a directory, read-only fs, etc.) along with the target directory path.","triggerScenarios":"Calling writeBytes (via writeBody, writeError, collectPprof, savePprofProfile) when the directory `filepath.Join(c.collectDir, dir)` cannot be created: parent path component is a file, permission denied, disk full/read-only filesystem.","commonSituations":"Running `nomad operator debug` as a non-root user targeting a -output dir owned by root; SELinux/AppArmor restrictions; the output path contains a regular file where a directory is expected; full or read-only disk on the node.","solutions":["Inspect the wrapped cause: permission denied means fix ownership/permissions (`chown`/`chmod`) on the output directory.","Check that no regular file exists at a path component of the target directory; remove or rename it.","Choose a writable output directory via the debug command's output flag, e.g. a path under the invoking user's home.","Verify the filesystem is not full or mounted read-only (`df -h`, `mount | grep <path>`)."],"exampleFix":"// before (shell)\nsudo nomad operator debug -output /root/debug\n// after\nnomad operator debug -output \"$HOME/debug\"","handlingStrategy":"validation","validationCode":"out := flagOutput\nif info, err := os.Stat(out); err == nil && !info.IsDir() {\n    return fmt.Errorf(\"output path %q exists and is not a directory\", out)\n}\nprobe := filepath.Join(out, \".write-test\")\nif err := os.WriteFile(probe, nil, 0o600); err != nil {\n    return fmt.Errorf(\"output dir %q not writable: %w\", out, err)\n}\nos.Remove(probe)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run the debug command as a user with write access to the output directory.","Pre-write-test the output directory in automation before collection.","Avoid output paths under read-only mounts (/proc, read-only volumes).","Check disk space before long-running captures."],"tags":["filesystem","permissions","directory","debug"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}