{"record":{"id":"6baaf0cd1ba1465f","repo":"ahmetb/kubectx","slug":"failed-to-read-previous-context-file-w","errorCode":null,"errorMessage":"failed to read previous context file: %w","messagePattern":"failed to read previous context file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kubectx/switch.go","lineNumber":98,"sourceCode":"\t}\n\n\tif prev != name {\n\t\tif err := writeLastContext(prevCtxFile, prev); err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to save previous context name: %w\", err)\n\t\t}\n\t}\n\treturn name, nil\n}\n\n// swapContext switches to previously switch context.\nfunc swapContext() (string, error) {\n\tprevCtxFile, err := kubectxPrevCtxFile()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to determine state file: %w\", err)\n\t}\n\tprev, err := readLastContext(prevCtxFile)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to read previous context file: %w\", err)\n\t}\n\tif prev == \"\" {\n\t\treturn \"\", errors.New(\"no previous context found\")\n\t}\n\treturn switchContext(prev)\n}\n","sourceCodeStart":80,"sourceCodeEnd":105,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/cmd/kubectx/switch.go#L80-L105","documentation":"readLastContext failed while loading the saved previous context for the '-' swap operation. The not-exists case is handled silently, so this fires on actual read errors: permission denied on the state file or an I/O error reading it.","triggerScenarios":"Thrown at cmd/kubectx/switch.go:98 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check permissions on the kubectx state file (~/.kube/kubectx or XDG state equivalent)","Remove the corrupted/locked state file — you lose only the previous-context memory","Fix filesystem issues on the home directory mount"],"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"}