hashicorp/nomad · error
Failed to write data to file %q, err: %w
Error message
Failed to write data to file %q, err: %w
What it means
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.
Source
Thrown at command/operator_debug.go:1423
return fmt.Errorf("failed to create parent directories of %q: %w", dirPath, err)
}
// Ensure filename doesn't escape the sandbox of the capture directory
escapes := escapingfs.PathEscapesSandbox(c.collectDir, filePath)
if escapes {
return fmt.Errorf("file path %q escapes capture directory %q", filePath, c.collectDir)
}
// Create the file
fh, err := os.Create(filePath)
if err != nil {
return fmt.Errorf("failed to create file %q, err: %w", filePath, err)
}
defer fh.Close()
_, err = fh.Write(data)
if err != nil {
return fmt.Errorf("Failed to write data to file %q, err: %w", filePath, err)
}
return nil
}
// newFilePath returns a validated filepath rooted in the provided directory and
// path. It has been checked that it falls inside the sandbox and has been added
// to the manifest tracking.
func (c *OperatorDebugCommand) newFilePath(dir, file string) (string, error) {
// Replace invalid characters in filename
filename := helper.CleanFilename(file, "_")
relativePath := filepath.Join(dir, filename)
c.manifest = append(c.manifest, relativePath)
dirPath := filepath.Join(c.collectDir, dir)
filePath := filepath.Join(dirPath, filename)
// Ensure parent directories existView on GitHub (pinned to 482b49bf1a)
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.
Example fix
// before (shell) nomad operator debug -output /var/log # 99% full // after df -h && nomad operator debug -output /var/tmp/debug
Defensive patterns
Strategy: fallback
Validate before calling
if usage, err := diskusage(dir); err == nil && usage.Free < minRequiredBytes {
return fmt.Errorf("insufficient space on %s: %d bytes free", dir, usage.Free)
} Try / catch
if err := c.writeBytes(dir, filename, resp, respErr); err != nil {
if strings.Contains(err.Error(), "no space left") {
// switch to an alternate output location or free space, then retry
}
return err
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Collecting debug bundles on nodes with nearly-full disks; NFS/EFS mounts timing out; hardware/storage failures on the node.
Related errors
- write error, wrote %d bytes of %d: %v
- could not copy file: %v
- failed to write snapshot file: %v
- unable to read rooted allocation directory
- can't seek to offset %d: %w
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/94ced950bc14af2b.
Report an issue: GitHub.