{"record":{"id":"1db9a047f9fe3b54","repo":"GoogleContainerTools/skaffold","slug":"writing-buffer-contents-to-file-w","errorCode":null,"errorMessage":"writing buffer contents to file: %w","messagePattern":"writing buffer contents to file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/event/v2/event.go","lineNumber":373,"sourceCode":"\tif err != nil {\n\t\treturn fmt.Errorf(\"opening %s: %w\", fp, err)\n\t}\n\tdefer f.Close()\n\n\t// Iterate over events, grabbing contents only from SkaffoldLogEvents\n\tvar contents bytes.Buffer\n\tfor _, ev := range handler.eventLog {\n\t\tif sle := ev.GetSkaffoldLogEvent(); sle != nil {\n\t\t\t// Strip ansi color sequences as this makes it easier to deal with when pasting into github issues\n\t\t\tif _, err = contents.WriteString(stripansi.Strip(sle.Message)); err != nil {\n\t\t\t\treturn fmt.Errorf(\"writing string to temporary buffer: %w\", err)\n\t\t\t}\n\t\t}\n\t}\n\n\t// Write contents of temporary buffer to file\n\tif _, err = f.Write(contents.Bytes()); err != nil {\n\t\treturn fmt.Errorf(\"writing buffer contents to file: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc lastLogFile(fp string) (string, error) {\n\tif fp != \"\" {\n\t\treturn fp, nil\n\t}\n\n\t// last log location unspecified, use ~/.skaffold/last.log\n\thome, err := homedir.Dir()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"retrieving home directory: %w\", err)\n\t}\n\treturn filepath.Join(home, constants.DefaultSkaffoldDir, \"last.log\"), nil\n}\n","sourceCodeStart":355,"sourceCodeEnd":390,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/event/v2/event.go#L355-L390","documentation":"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.","triggerScenarios":"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.","commonSituations":"Small ephemeral CI disks filling up; network storage disconnecting; writing to tmpfs that exhausted its size limit; hardware/device errors.","solutions":["Check free disk space on the destination filesystem and retry after freeing space.","Verify the target filesystem did not transition to read-only or unmount (dmesg, mount output).","Write the log to a different local filesystem and retry."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if err := checkDiskSpace(filepath.Dir(fp), uint64(64<<20)); err != nil {\n    return fmt.Errorf(\"insufficient space for %s: %w\", fp, err)\n}","typeGuard":null,"tryCatchPattern":"if err := event.SaveLastLog(fp); err != nil {\n    if strings.Contains(err.Error(), \"writing buffer contents\") {\n        time.Sleep(time.Second)\n        return event.SaveLastLog(fp) // one retry after transient I/O error\n    }\n    return err\n}","preventionTips":["Monitor free disk space on the destination filesystem","Avoid saving to tmpfs or network mounts with tight limits","Alert on filesystems transitioning to read-only"],"tags":["filesystem","io","logs"],"backgroundTag":"file-write-failed","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}