ahmetb/kubectx · error
failed to write temp kubeconfig: %w
Error message
failed to write temp kubeconfig: %w
What it means
Writing the extracted kubeconfig bytes to the already-created temp file failed (tmpFile.Write). The file was created successfully, so this is a mid-write I/O failure: disk full or the file descriptor became invalid.
Source
Thrown at cmd/kubectx/shell_session.go:89
if err != nil {
return err
}
if cleanup != nil {
defer cleanup()
}
}
// Write kubeconfig to temp file.
tmpFile, err := os.CreateTemp("", "kubectx-shell-*.yaml")
if err != nil {
return fmt.Errorf("failed to create temp kubeconfig file: %w", err)
}
tmpPath := tmpFile.Name()
defer os.Remove(tmpPath)
if _, err := tmpFile.Write(data); err != nil {
tmpFile.Close()
return fmt.Errorf("failed to write temp kubeconfig: %w", err)
}
tmpFile.Close()
// Print entry message.
s.printEntry(stderr, s.target)
// Detect and start shell.
shellBin := detectShell()
cmd := exec.Command(shellBin)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Env = append(os.Environ(),
append([]string{
"KUBECONFIG=" + tmpPath,
env.EnvIsolatedShell + "=1",
}, s.extraEnv...)...,
)View on GitHub (pinned to 12ad6fb22e)
Solutions
- Free space in the temp directory /tmp or TMPDIR
- Check dmesg for I/O or filesystem errors on the temp mount
- Retry after freeing space; the temp file is cleaned up automatically
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at cmd/kubectx/shell_session.go:89 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/a74ce36b9cee7caa.
Report an issue: GitHub.