wagoodman/dive · error
cannot write to export file: %w
Error message
cannot write to export file: %w
What it means
Returned when writing the already-marshalled JSON bytes to the opened export file fails. The file was successfully created, but the actual Write call errored — typically disk full (ENOSPC), quota exceeded, or the file descriptor invalidated by an external actor. Note the file is opened without O_TRUNC, so pre-existing longer content can also leave stale trailing bytes on success.
Source
Thrown at cmd/dive/cli/internal/command/adapter/exporter.go:60
})
bytes, err := export.NewExport(analysis).Marshal()
if err != nil {
mon.SetError(err)
return fmt.Errorf("cannot marshal export payload: %w", err)
} else {
mon.SetCompleted()
}
file, err := e.filesystem.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644)
if err != nil {
return fmt.Errorf("cannot open export file: %w", err)
}
defer file.Close()
_, err = file.Write(bytes)
if err != nil {
return fmt.Errorf("cannot write to export file: %w", err)
}
return nil
}
View on GitHub (pinned to d6c691947f)
Solutions
- Check the wrapped error — 'no space left on device' means freeing disk or pointing --json elsewhere
- Verify the target filesystem is writable and not quota-capped (df -h <dir>)
- Re-run the export once space is freed; the payload is rebuilt from the in-memory analysis so a retry is safe
- Operators of the exporter can add O_TRUNC to the OpenFile flags to avoid stale trailing bytes from previous longer files
Example fix
// before file, err := e.filesystem.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644) // after (also truncate stale content) file, err := e.filesystem.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
Defensive patterns
Strategy: retry
Validate before calling
// check free space before writing large exports
var stat syscall.Statfs_t
if err := syscall.Statfs(filepath.Dir(path), &stat); err == nil {
free := stat.Bavail * uint64(stat.Bsize)
if free < uint64(len(payloadEstimate)) { return fmt.Errorf("insufficient space for export") }
} Try / catch
err := exporter.ExportTo(ctx, analysis, path)
if err != nil && strings.Contains(err.Error(), "cannot write to export file") {
// transient ENOSPC/EIO: free space or change path, then retry once
err = exporter.ExportTo(ctx, analysis, altPath)
}
if err != nil { return err } Prevention
- Monitor disk space on CI runners that export large JSON payloads
- Write exports to a dedicated artifacts volume with quota headroom
- Retry with an alternate path when the write target is unreliable
When it happens
Trigger: dive --json <path> where the disk fills during the write, a filesystem quota is hit, the filesystem is read-only remounted between open and write, or an antivirus/container runtime holds/invalidates the fd.
Common situations: CI runners with small ephemeral disks writing large image exports; exporting into a full volume mount; overlay filesystems in containers hitting disk pressure.
Related errors
- cannot open export file: %w
- cannot export analysis: %w
- directory for JSON export does not exist: %s
- cannot marshal export payload: %w
- unable to read file: %w
AI-assisted analysis of wagoodman/dive@d6c691947f (2026-08-15).
Data as JSON: /api/errors/619cae32fe35ced5.
Report an issue: GitHub.