GoogleContainerTools/skaffold · error

writing buffer contents to file: %w

Error message

writing buffer contents to file: %w

What it means

After collecting all log messages into a bytes.Buffer, SaveLastLog flushes them with f.Write(contents.Bytes()). This error wraps a failure of that final write to the already-opened file — disk full, I/O error, device error, or the handle being invalid. The function aborts, possibly after a partial write.

Source

Thrown at pkg/skaffold/event/v2/event.go:373

	if err != nil {
		return fmt.Errorf("opening %s: %w", fp, err)
	}
	defer f.Close()

	// Iterate over events, grabbing contents only from SkaffoldLogEvents
	var contents bytes.Buffer
	for _, ev := range handler.eventLog {
		if sle := ev.GetSkaffoldLogEvent(); sle != nil {
			// Strip ansi color sequences as this makes it easier to deal with when pasting into github issues
			if _, err = contents.WriteString(stripansi.Strip(sle.Message)); err != nil {
				return fmt.Errorf("writing string to temporary buffer: %w", err)
			}
		}
	}

	// Write contents of temporary buffer to file
	if _, err = f.Write(contents.Bytes()); err != nil {
		return fmt.Errorf("writing buffer contents to file: %w", err)
	}
	return nil
}

func lastLogFile(fp string) (string, error) {
	if fp != "" {
		return fp, nil
	}

	// last log location unspecified, use ~/.skaffold/last.log
	home, err := homedir.Dir()
	if err != nil {
		return "", fmt.Errorf("retrieving home directory: %w", err)
	}
	return filepath.Join(home, constants.DefaultSkaffoldDir, "last.log"), nil
}

View on GitHub (pinned to a1189de023)

Solutions

  1. Check free disk space on the destination filesystem and retry after freeing space.
  2. Verify the target filesystem did not transition to read-only or unmount (dmesg, mount output).
  3. Write the log to a different local filesystem and retry.
Defensive patterns

Strategy: retry

Validate before calling

if err := checkDiskSpace(filepath.Dir(fp), uint64(64<<20)); err != nil {
    return fmt.Errorf("insufficient space for %s: %w", fp, err)
}

Try / catch

if err := event.SaveLastLog(fp); err != nil {
    if strings.Contains(err.Error(), "writing buffer contents") {
        time.Sleep(time.Second)
        return event.SaveLastLog(fp) // one retry after transient I/O error
    }
    return err
}

Prevention

When it happens

Trigger: Calling SaveLastLog when the file is opened successfully but the flush fails: disk quota exceeded, filesystem went read-only or was unmounted mid-write, or I/O errors on the underlying device.

Common situations: Small ephemeral CI disks filling up; network storage disconnecting; writing to tmpfs that exhausted its size limit; hardware/device errors.

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


AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05). Data as JSON: /api/errors/1db9a047f9fe3b54. Report an issue: GitHub.