{"record":{"id":"cca2eb4788411ee9","repo":"GoogleContainerTools/skaffold","slug":"writing-string-w-cca2eb","errorCode":null,"errorMessage":"writing string: %w","messagePattern":"writing string: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/event/v2/event.go","lineNumber":332,"sourceCode":"\thandler.logLock.Lock()\n\t// Ensure that the filepath provided has the directories available when attemping to save the file.\n\tdir := filepath.Dir(fp)\n\tif err := os.MkdirAll(dir, 0700); err != nil {\n\t\treturn fmt.Errorf(\"unable to create directory %q: %w\", dir, err)\n\t}\n\tf, err := os.OpenFile(fp, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"opening %s: %w\", fp, err)\n\t}\n\tdefer f.Close()\n\tmarshaller := jsonpb.Marshaler{}\n\tfor _, ev := range handler.eventLog {\n\t\tcontents := bytes.NewBuffer([]byte{})\n\t\tif err := marshaller.Marshal(contents, ev); err != nil {\n\t\t\treturn fmt.Errorf(\"marshalling event: %w\", err)\n\t\t}\n\t\tif _, err := f.WriteString(contents.String() + \"\\n\"); err != nil {\n\t\t\treturn fmt.Errorf(\"writing string: %w\", err)\n\t\t}\n\t}\n\thandler.logLock.Unlock()\n\treturn nil\n}\n\n// SaveLastLog writes the output from the previous run to the specified filepath\nfunc SaveLastLog(fp string) error {\n\thandler.logLock.Lock()\n\tdefer handler.logLock.Unlock()\n\n\t// Create file to write logs to\n\tfp, err := lastLogFile(fp)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"getting last log file %w\", err)\n\t}\n\t// Ensure that the filepath provided has the directories available when attemping to save the file.\n\tdir := filepath.Dir(fp)","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/event/v2/event.go#L314-L350","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check disk space (df -h) and free space on the target filesystem, then retry.","Verify the destination path's filesystem is writable by the current user.","Save to a different, local, writable directory."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"info, err := os.Stat(path)\nif err == nil && info.IsDir() {\n    return fmt.Errorf(\"%s is a directory\", path)\n}\nif err := unix.Access(filepath.Dir(path), unix.W_OK); err != nil {\n    return fmt.Errorf(\"%s is not writable: %w\", filepath.Dir(path), err)\n}","typeGuard":null,"tryCatchPattern":"if err := event.SaveEventsToFile(path); err != nil {\n    if strings.Contains(err.Error(), \"writing string\") {\n        // fall back to a temp location\n        return event.SaveEventsToFile(filepath.Join(os.TempDir(), \"events.log\"))\n    }\n    return err\n}","preventionTips":["Check disk space before long-running save operations","Save event files to a known-writable local directory","Do not close the file handle concurrently while writing"],"tags":["filesystem","io","events"],"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"}