{"record":{"id":"e1f9f929ddd4abbc","repo":"ahmetb/kubectx","slug":"home-or-userprofile-environment-variable-not-set","errorCode":null,"errorMessage":"HOME or USERPROFILE environment variable not set","messagePattern":"HOME or USERPROFILE environment variable not set","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kubectx/state.go","lineNumber":29,"sourceCode":"// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"os\"\n\t\"path/filepath\"\n\n\t\"github.com/ahmetb/kubectx/internal/cmdutil\"\n)\n\nfunc kubectxPrevCtxFile() (string, error) {\n\tdir := cmdutil.CacheDir()\n\tif dir == \"\" {\n\t\treturn \"\", errors.New(\"HOME or USERPROFILE environment variable not set\")\n\t}\n\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)","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/cmd/kubectx/state.go#L11-L47","documentation":"Sentinel error in kubectxPrevCtxFile: cmdutil.CacheDir() returned an empty string because neither HOME nor USERPROFILE is set in the environment, so the tool cannot locate its cache directory to store/read the previous-context state file (~/.cache/kubectx/kubectx). Swap and switch operations depend on this path.","triggerScenarios":"Thrown at cmd/kubectx/state.go:29 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set the HOME environment variable (USERPROFILE on Windows) before running kubectx","Ensure the shell environment is complete (e.g. in cron/CI set HOME explicitly)"],"exampleFix":null,"handlingStrategy":"validation","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"}