hashicorp/nomad · error
failed to write bytes to eventstream.json; bytes written: %d
Error message
failed to write bytes to eventstream.json; bytes written: %d, Err: %w
What it means
After successfully marshaling an event, captureEventStream writes the JSON bytes to the open eventstream.json file handle. If fh.Write fails (bytes may be partially written, n is reported in the message), the error is appended to the multierror and the event loop breaks out. This indicates the capture destination became unwritable mid-capture.
Source
Thrown at command/operator_debug.go:992
if event.IsHeartbeat() {
heartbeatCount++
continue
}
for _, e := range event.Events {
eventCount++
c.verboseOutf("Event: %4d, Index: %d, Topic: %-10s, Type: %s, FilterKeys: %s", eventCount, e.Index, e.Topic, e.Type, e.FilterKeys)
bytes, err := json.Marshal(e)
if err != nil {
errCount++
mErrs = multierror.Append(mErrs, fmt.Errorf("failed to marshal json from Topic: %s, Type: %s, Err: %w", e.Topic, e.Type, err))
}
n, err := fh.Write(bytes)
if err != nil {
errCount++
mErrs = multierror.Append(mErrs, fmt.Errorf("failed to write bytes to eventstream.json; bytes written: %d, Err: %w", n, err))
break
}
n, err = fh.WriteString("\n")
if err != nil {
errCount++
mErrs = multierror.Append(mErrs, fmt.Errorf("failed to write string to eventstream.json; chars written: %d, Err: %w", n, err))
}
}
case <-c.ctx.Done():
c.verboseOutf("Event stream captured %d events, %d frames, %d heartbeats, %d errors", eventCount, channelEventCount, heartbeatCount, errCount)
return mErrs.ErrorOrNil()
}
}
}
// collectAgentHosts calls collectAgentHost for each selected node
func (c *OperatorDebugCommand) collectAgentHosts(client *api.Client) {
for _, n := range c.nodeIDs {View on GitHub (pinned to 482b49bf1a)
Solutions
- Free disk space or point the capture at a directory with room (df -h; choose a larger -output target)
- Check the partial byte count n in the message to assess how much of the event was written
- Verify the capture directory still exists and is writable during the run (ls -ld, no concurrent cleanup jobs)
- Re-run the capture after fixing storage; the multierror lists how many events were affected via errCount
Defensive patterns
Strategy: try-catch
Validate before calling
// preflight
if st, err := os.Stat(outputDir); err != nil || !st.IsDir() {
return fmt.Errorf("output dir %s unavailable", outputDir)
}
if du, err := checkFreeSpace(outputDir); err != nil || du < minBytes {
return fmt.Errorf("insufficient space in %s", outputDir)
} Try / catch
n, err := fh.Write(bytes)
if err != nil {
errs = multierror.Append(errs, fmt.Errorf("failed to write bytes to eventstream.json; bytes written: %d, Err: %w", n, err))
break // stop consuming a broken file handle
} Prevention
- Ensure the output filesystem has ample free space before long captures
- Don't delete or rotate the capture directory while the command runs
- Avoid quota-limited/tmpfs volumes for capture output
When it happens
Trigger: fh.Write returns an error: disk full, capture directory removed while capturing, file descriptor closed, permission changed, or I/O error on the underlying filesystem.
Common situations: /tmp or the -output dir filling up during long captures; someone deleting the capture directory while debug runs; running on a read-only or quota-limited filesystem; container tmpfs size limits.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- failed to write string to eventstream.json; chars written: %
- unable to read rooted allocation directory
- can't seek to offset %d: %w
- Couldn't copy %q to %q: %w
- error writing to file %q: %w
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/d96eae8c5f563ceb.
Report an issue: GitHub.