{"record":{"id":"6bd5f9c6ab08f90c","repo":"GoogleContainerTools/skaffold","slug":"unable-to-create-directory-q-w","errorCode":null,"errorMessage":"unable to create directory %q: %w","messagePattern":"unable to create directory %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/event/event.go","lineNumber":837,"sourceCode":"\nfunc InititializationFailed(err error) {\n\thandler.handle(&proto.Event{\n\t\tEventType: &proto.Event_TerminationEvent{\n\t\t\tTerminationEvent: &proto.TerminationEvent{\n\t\t\t\tStatus: Failed,\n\t\t\t\tErr:    sErrors.ActionableErr(handler.cfg, constants.Init, err),\n\t\t\t},\n\t\t},\n\t})\n}\n\n// SaveEventsToFile saves the current event log to the filepath provided\nfunc SaveEventsToFile(fp string) error {\n\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","sourceCodeStart":819,"sourceCodeEnd":855,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/event/event.go#L819-L855","documentation":"SaveEventsToFile persists the in-memory event log to a JSON file. It first creates the parent directories of the provided filepath with os.MkdirAll(dir, 0700); if that fails the error is wrapped as 'unable to create directory %q'. This usually indicates a filesystem-level problem, not a skaffold bug.","triggerScenarios":"Calling SaveEventsToFile with a path whose parent directory cannot be created: missing parent write permission, a file component existing where a directory is expected (ENOTDIR/EEXIST), read-only filesystem, or an invalid path component.","commonSituations":"Passing an event log path inside a read-only container filesystem or read-only mount; a regular file already occupies a path segment of the target directory; running as a user without write access to the output location; disk full on tmpfs.","solutions":["Check whether a file exists at any segment of the target directory path and remove/rename it","Verify write permission on the nearest existing parent directory (ls -ld <dir>)","Write the event log to a writable location (e.g. $HOME or a mounted volume) instead of a read-only path","Inspect the wrapped inner error (ENOENT/EACCES/ENOTDIR) to pinpoint which path component fails"],"exampleFix":"// before\nSaveEventsToFile(\"/proc/1/events.json\")\n// after\nSaveEventsToFile(filepath.Join(os.TempDir(), \"skaffold-events.json\"))","handlingStrategy":"validation","validationCode":"dir := filepath.Dir(fp)\nif info, err := os.Stat(dir); err == nil && !info.IsDir() {\n    return fmt.Errorf(\"%s exists and is not a directory\", dir)\n}\nif err := os.MkdirAll(dir, 0700); err != nil {\n    return fmt.Errorf(\"pre-check mkdir failed: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := SaveEventsToFile(fp); err != nil {\n    var pErr *fs.PathError\n    if errors.As(err, &pErr) {\n        log.Warnf(\"event log not saved (%s: %v), continuing\", pErr.Path, pErr.Err)\n        return nil\n    }\n    return err\n}","preventionTips":["Choose event-log destinations under a guaranteed-writable directory (os.TempDir, $HOME)","Never point the log path at special filesystems (/proc, /sys)","Ensure no regular file occupies a directory segment of the path","In containers, mount a volume for logs"],"tags":["filesystem","events","mkdir"],"backgroundTag":"permission-denied","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"}