{"record":{"id":"ecdf624945b14b83","repo":"ahmetb/kubectx","slug":"write-error-w-ecdf62","errorCode":null,"errorMessage":"write error: %w","messagePattern":"write error: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kubectx/version.go","lineNumber":18,"sourceCode":"package main\n\nimport (\n\t\"fmt\"\n\t\"io\"\n)\n\nvar (\n\tversion = \"v0.0.0+unknown\" // populated by goreleaser\n)\n\n// VersionOp describes printing version string.\ntype VersionOp struct{}\n\nfunc (_ VersionOp) Run(stdout, _ io.Writer) error {\n\t_, err := fmt.Fprintf(stdout, \"%s\\n\", version)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"write error: %w\", err)\n\t}\n\treturn nil\n}\n","sourceCodeStart":1,"sourceCodeEnd":22,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/cmd/kubectx/version.go#L1-L22","documentation":"VersionOp.Run prints the build version string to stdout via fmt.Fprintf. If the underlying write to the output stream fails, the error is wrapped as \"write error: %w\" and returned to the caller. This indicates the destination stream (e.g. a closed or broken pipe, full disk, or redirected file) could not accept the output.","triggerScenarios":"Calling kubectx version (or VersionOp.Run) with stdout pointing to a stream that errors on write, such as a closed pipe (e.g. `kubectx version | head -0`), a full disk, or an invalid file descriptor.","commonSituations":"Piping kubectx output into a command that exits early and closes the pipe (SIGPIPE/EPIPE); writing to a redirect target on a full filesystem; CI logs with a broken output stream.","solutions":["Re-run the command with stdout connected to a terminal or a valid file to confirm the stream works","Check for a full disk (df -h) or permission issues on the redirect target","Update kubectx if your shell/pipe setup kills the process before the write completes","If writing Go, check the wrapped error (%w) for EPIPE vs EACCES to determine the real cause"],"exampleFix":"// before\nkubectx version | head -0   // closes pipe early -> write error\n// after\nkubectx version             // write to a healthy stream","handlingStrategy":"try-catch","validationCode":"// Go: check the output stream before running\nif f, ok := stdout.(*os.File); ok {\n    if _, err := f.Stat(); err != nil {\n        return fmt.Errorf(\"stdout unusable: %w\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := VersionOp{}.Run(stdout, stderr); err != nil {\n    var werr *os.PathError\n    if errors.As(err, &werr) && errors.Is(werr.Err, syscall.EPIPE) {\n        // broken pipe: consumer closed early, treat as non-fatal\n        return nil\n    }\n    return err\n}","preventionTips":["Avoid piping version output into commands that exit immediately","Check disk space when redirecting output to files","In wrappers, inspect errors.Is(err, syscall.EPIPE) to handle SIGPIPE gracefully","Log stderr rather than only stdout in CI"],"tags":["go","io","broken-pipe"],"backgroundTag":"write-failed-broken-pipe","analyzedSha":"12ad6fb22e8c546ee2b54e7de38aa51c906832f7","analyzedAt":"2026-09-02T12:23:10.107Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T16:17:10.729Z"}