ahmetb/kubectx · error
failed to write temp kubeconfig: %w
Error message
failed to write temp kubeconfig: %w
What it means
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.
Source
Thrown at cmd/kubectx/readonly_shell.go:59
fmt.Fprintf(w, "%s kubectl context is %s in READ-ONLY mode — type 'exit' to leave.\n",
badgeColor.Sprint("[READONLY SHELL]"), printer.WarningColor.Sprint(ctxName))
},
printExit: func(w io.Writer, prevCtx string) {
fmt.Fprintf(w, "%s kubectl context is now %s.\n",
badgeColor.Sprint("[READONLY SHELL EXITED]"), printer.WarningColor.Sprint(prevCtx))
},
transformKubeconfig: func(data []byte) ([]byte, func(), error) {
// Write original kubeconfig to temp file for the proxy to load TLS/auth.
origFile, err := os.CreateTemp("", "kubectx-readonly-orig-*.yaml")
if err != nil {
return nil, nil, fmt.Errorf("failed to create temp kubeconfig file: %w", err)
}
origPath := origFile.Name()
if _, err := origFile.Write(data); err != nil {
origFile.Close()
os.Remove(origPath)
return nil, nil, fmt.Errorf("failed to write temp kubeconfig: %w", err)
}
origFile.Close()
// Start the readonly proxy.
p, err := proxy.Start(proxy.Config{
KubeconfigPath: origPath,
ContextName: op.Target,
})
if err != nil {
os.Remove(origPath)
return nil, nil, fmt.Errorf("failed to start readonly proxy: %w", err)
}
// Rewrite kubeconfig to point to the proxy.
rewritten, err := proxy.RewriteKubeconfig(data, p.Addr())
if err != nil {
p.Shutdown(context.Background())
os.Remove(origPath)View on GitHub (pinned to 12ad6fb22e)
Solutions
- Check disk space and temp directory health
- Retry the readonly shell after resolving the I/O error
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at cmd/kubectx/readonly_shell.go:59 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of ahmetb/kubectx@12ad6fb22e (2026-09-02).
Data as JSON: /api/errors/b7bbf13ecb2fc98c.
Report an issue: GitHub.