{"record":{"id":"a6d14a262b6ab51b","repo":"ahmetb/kubectx","slug":"failed-to-create-parent-directories-w","errorCode":null,"errorMessage":"failed to create parent directories: %w","messagePattern":"failed to create parent directories: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kubectx/state.go","lineNumber":49,"sourceCode":"\treturn filepath.Join(dir, \"kubectx\"), nil\n}\n\n// readLastContext returns the saved previous context\n// if the state file exists, otherwise returns \"\".\nfunc readLastContext(path string) (string, error) {\n\tb, err := os.ReadFile(path)\n\tif os.IsNotExist(err) {\n\t\treturn \"\", nil\n\t}\n\treturn string(b), err\n}\n\n// writeLastContext saves the specified value to the state file.\n// It creates missing parent directories.\nfunc writeLastContext(path, value string) error {\n\tdir := filepath.Dir(path)\n\tif err := os.MkdirAll(dir, 0755); err != nil {\n\t\treturn fmt.Errorf(\"failed to create parent directories: %w\", err)\n\t}\n\treturn os.WriteFile(path, []byte(value), 0644)\n}\n","sourceCodeStart":31,"sourceCodeEnd":53,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/cmd/kubectx/state.go#L31-L53","documentation":"Returned by writeLastContext when os.MkdirAll fails to create the missing parent directories of the state-file path (the kubectx state directory under the user config/cache dir). It fires when the directory cannot be created due to permissions, an existing non-directory file at that path, or an unwritable parent — meaning the previous-context value cannot be persisted.","triggerScenarios":"Thrown at cmd/kubectx/state.go:49 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check write permission on the home directory / state file parent (usually ~/.kube)","Fix ownership or chmod of the parent directory","If HOME is unset or points somewhere unwritable (CI, containers), set HOME to a writable path"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"12ad6fb22e8c546ee2b54e7de38aa51c906832f7","analyzedAt":"2026-09-02T12:23:10.107Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T16:17:10.729Z"}