GoogleContainerTools/skaffold · error

writing string: %w

Error message

writing string: %w

What it means

After successfully marshaling an event to JSON, SaveEventsToFile writes the line (plus newline) to the destination file with f.WriteString. This error wraps any failure of that write — disk full, closed handle, permission or I/O error on the target file. The save operation stops at the first event whose line cannot be written.

Source

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

	handler.logLock.Lock()
	// Ensure that the filepath provided has the directories available when attemping to save the file.
	dir := filepath.Dir(fp)
	if err := os.MkdirAll(dir, 0700); err != nil {
		return fmt.Errorf("unable to create directory %q: %w", dir, err)
	}
	f, err := os.OpenFile(fp, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
	if err != nil {
		return fmt.Errorf("opening %s: %w", fp, err)
	}
	defer f.Close()
	marshaller := jsonpb.Marshaler{}
	for _, ev := range handler.eventLog {
		contents := bytes.NewBuffer([]byte{})
		if err := marshaller.Marshal(contents, ev); err != nil {
			return fmt.Errorf("marshalling event: %w", err)
		}
		if _, err := f.WriteString(contents.String() + "\n"); err != nil {
			return fmt.Errorf("writing string: %w", err)
		}
	}
	handler.logLock.Unlock()
	return nil
}

// SaveLastLog writes the output from the previous run to the specified filepath
func SaveLastLog(fp string) error {
	handler.logLock.Lock()
	defer handler.logLock.Unlock()

	// Create file to write logs to
	fp, err := lastLogFile(fp)
	if err != nil {
		return fmt.Errorf("getting last log file %w", err)
	}
	// Ensure that the filepath provided has the directories available when attemping to save the file.
	dir := filepath.Dir(fp)

View on GitHub (pinned to a1189de023)

Solutions

  1. Check disk space (df -h) and free space on the target filesystem, then retry.
  2. Verify the destination path's filesystem is writable by the current user.
  3. Save to a different, local, writable directory.
Defensive patterns

Strategy: validation

Validate before calling

info, err := os.Stat(path)
if err == nil && info.IsDir() {
    return fmt.Errorf("%s is a directory", path)
}
if err := unix.Access(filepath.Dir(path), unix.W_OK); err != nil {
    return fmt.Errorf("%s is not writable: %w", filepath.Dir(path), err)
}

Try / catch

if err := event.SaveEventsToFile(path); err != nil {
    if strings.Contains(err.Error(), "writing string") {
        // fall back to a temp location
        return event.SaveEventsToFile(filepath.Join(os.TempDir(), "events.log"))
    }
    return err
}

Prevention

When it happens

Trigger: Calling SaveEventsToFile(path) where the file was opened but the write fails: read-only filesystem, disk quota/full disk, file deleted or locked after OpenFile, or f already closed by an earlier deferred Close.

Common situations: Saving to /tmp or a mount that filled up during a long skaffold session; CI containers with tiny ephemeral disks; saving onto read-only volumes or network mounts that dropped.

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/cca2eb4788411ee9. Report an issue: GitHub.