{"record":{"id":"94ced950bc14af2b","repo":"hashicorp/nomad","slug":"failed-to-write-data-to-file-q-err-w","errorCode":null,"errorMessage":"Failed to write data to file %q, err: %w","messagePattern":"Failed to write data to file %q, err: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/operator_debug.go","lineNumber":1423,"sourceCode":"\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)\n\t}\n\treturn nil\n}\n\n// newFilePath returns a validated filepath rooted in the provided directory and\n// path. It has been checked that it falls inside the sandbox and has been added\n// to the manifest tracking.\nfunc (c *OperatorDebugCommand) newFilePath(dir, file string) (string, error) {\n\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","sourceCodeStart":1405,"sourceCodeEnd":1441,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/operator_debug.go#L1405-L1441","documentation":"Thrown by `writeBytes` when the write to the already-created file fails. The file was opened successfully but `fh.Write(data)` returned an error — typically disk full (ENOSPC), I/O error, or the file descriptor becoming invalid. Nomad reports the path along with the OS error.","triggerScenarios":"fh.Write failing mid-collection: no space left on device during a large debug bundle, underlying storage I/O error, or write to a file on a network mount that dropped.","commonSituations":"Collecting debug bundles on nodes with nearly-full disks; NFS/EFS mounts timing out; hardware/storage failures on the node.","solutions":["Free disk space on the volume holding the capture directory (ENOSPC is the most common cause).","Write the bundle to a different, larger volume via the output flag.","If on a network filesystem, retry writing to local disk instead.","Check `dmesg`/system logs for underlying block-device I/O errors and address hardware issues."],"exampleFix":"// before (shell)\nnomad operator debug -output /var/log   # 99% full\n// after\ndf -h && nomad operator debug -output /var/tmp/debug","handlingStrategy":"fallback","validationCode":"if usage, err := diskusage(dir); err == nil && usage.Free < minRequiredBytes {\n    return fmt.Errorf(\"insufficient space on %s: %d bytes free\", dir, usage.Free)\n}","typeGuard":null,"tryCatchPattern":"if err := c.writeBytes(dir, filename, resp, respErr); err != nil {\n    if strings.Contains(err.Error(), \"no space left\") {\n        // switch to an alternate output location or free space, then retry\n    }\n    return err\n}","preventionTips":["Check free disk space before starting bundle collection and enforce a threshold in automation.","Prefer local disk over network mounts for debug output.","Alert on disks above ~90% utilization on nodes where captures run.","Clean up old debug bundles to keep space available."],"tags":["filesystem","disk-full","io","debug"],"backgroundTag":"disk-full-write-failed","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"}