{"record":{"id":"b7bbf13ecb2fc98c","repo":"ahmetb/kubectx","slug":"failed-to-write-temp-kubeconfig-w","errorCode":null,"errorMessage":"failed to write temp kubeconfig: %w","messagePattern":"failed to write temp kubeconfig: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kubectx/readonly_shell.go","lineNumber":59,"sourceCode":"\t\t\tfmt.Fprintf(w, \"%s kubectl context is %s in READ-ONLY mode — type 'exit' to leave.\\n\",\n\t\t\t\tbadgeColor.Sprint(\"[READONLY SHELL]\"), printer.WarningColor.Sprint(ctxName))\n\t\t},\n\t\tprintExit: func(w io.Writer, prevCtx string) {\n\t\t\tfmt.Fprintf(w, \"%s kubectl context is now %s.\\n\",\n\t\t\t\tbadgeColor.Sprint(\"[READONLY SHELL EXITED]\"), printer.WarningColor.Sprint(prevCtx))\n\t\t},\n\t\ttransformKubeconfig: func(data []byte) ([]byte, func(), error) {\n\t\t\t// Write original kubeconfig to temp file for the proxy to load TLS/auth.\n\t\t\torigFile, err := os.CreateTemp(\"\", \"kubectx-readonly-orig-*.yaml\")\n\t\t\tif err != nil {\n\t\t\t\treturn nil, nil, fmt.Errorf(\"failed to create temp kubeconfig file: %w\", err)\n\t\t\t}\n\t\t\torigPath := origFile.Name()\n\n\t\t\tif _, err := origFile.Write(data); err != nil {\n\t\t\t\torigFile.Close()\n\t\t\t\tos.Remove(origPath)\n\t\t\t\treturn nil, nil, fmt.Errorf(\"failed to write temp kubeconfig: %w\", err)\n\t\t\t}\n\t\t\torigFile.Close()\n\n\t\t\t// Start the readonly proxy.\n\t\t\tp, err := proxy.Start(proxy.Config{\n\t\t\t\tKubeconfigPath: origPath,\n\t\t\t\tContextName:    op.Target,\n\t\t\t})\n\t\t\tif err != nil {\n\t\t\t\tos.Remove(origPath)\n\t\t\t\treturn nil, nil, fmt.Errorf(\"failed to start readonly proxy: %w\", err)\n\t\t\t}\n\n\t\t\t// Rewrite kubeconfig to point to the proxy.\n\t\t\trewritten, err := proxy.RewriteKubeconfig(data, p.Addr())\n\t\t\tif err != nil {\n\t\t\t\tp.Shutdown(context.Background())\n\t\t\t\tos.Remove(origPath)","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/cmd/kubectx/readonly_shell.go#L41-L77","documentation":"Wrapper error in transformKubeconfig: writing the original kubeconfig bytes to the temp file failed (short write or I/O error). The temp file is closed and removed before returning; the readonly shell setup aborts with the cause wrapped in %w.","triggerScenarios":"Thrown at cmd/kubectx/readonly_shell.go:59 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check disk space and temp directory health","Retry the readonly shell after resolving the I/O error"],"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"}