From 91ae9f7436df7d63d7a448c45dce9fa27bf62d8b Mon Sep 17 00:00:00 2001 From: mitchell Date: Tue, 29 Oct 2024 13:20:04 -0400 Subject: [PATCH 1/2] Do not log JSON output pipe errors to rollbar. The system is hanging up on us and there is nothing we can do about it. --- internal/output/json.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/internal/output/json.go b/internal/output/json.go index 17aa06fd74..1d572c1a42 100644 --- a/internal/output/json.go +++ b/internal/output/json.go @@ -2,8 +2,11 @@ package output import ( "encoding/json" + "errors" "fmt" "io" + "runtime" + "syscall" "github.com/ActiveState/cli/internal/colorize" "github.com/ActiveState/cli/internal/locale" @@ -63,7 +66,11 @@ func (f *JSON) Fprint(writer io.Writer, value interface{}) { _, err := writer.Write(b) if err != nil { - multilog.Error("Could not write json output, error: %v", err) + if isPipeClosedError(err) { + logging.Error("Could not write json output, error: %v", err) // do not log to rollbar + } else { + multilog.Error("Could not write json output, error: %v", err) + } } } @@ -92,8 +99,22 @@ func (f *JSON) Error(value interface{}) { _, err = f.cfg.OutWriter.Write(b) if err != nil { - multilog.Error("Could not write json output, error: %v", err) + if isPipeClosedError(err) { + logging.Error("Could not write json output, error: %v", err) // do not log to rollbar + } else { + multilog.Error("Could not write json output, error: %v", err) + } + } +} + +func isPipeClosedError(err error) bool { + pipeErr := errors.Is(err, syscall.EPIPE) + if runtime.GOOS == "windows" && errors.Is(err, syscall.Errno(242)) { + // Note: 232 is Windows error code ERROR_NO_DATA, "The pipe is being closed". + // See https://go.dev/src/os/pipe_test.go + pipeErr = true } + return pipeErr } // Notice is ignored by JSON, as they are considered as non-critical output and there's currently no reliable way to From 716f1ee3670638e392010cd65b4c269e2ac2d51a Mon Sep 17 00:00:00 2001 From: mitchell Date: Wed, 30 Oct 2024 09:47:22 -0400 Subject: [PATCH 2/2] Use the correct error code. --- internal/output/json.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/output/json.go b/internal/output/json.go index 1d572c1a42..ad2b8e2939 100644 --- a/internal/output/json.go +++ b/internal/output/json.go @@ -109,7 +109,7 @@ func (f *JSON) Error(value interface{}) { func isPipeClosedError(err error) bool { pipeErr := errors.Is(err, syscall.EPIPE) - if runtime.GOOS == "windows" && errors.Is(err, syscall.Errno(242)) { + if runtime.GOOS == "windows" && errors.Is(err, syscall.Errno(232)) { // Note: 232 is Windows error code ERROR_NO_DATA, "The pipe is being closed". // See https://go.dev/src/os/pipe_test.go pipeErr = true