Skip to content

Commit

Permalink
Do not log JSON output pipe errors to rollbar.
Browse files Browse the repository at this point in the history
The system is hanging up on us and there is nothing we can do about it.
  • Loading branch information
mitchell-as committed Oct 29, 2024
1 parent f40316e commit 91ae9f7
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions internal/output/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
}
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 91ae9f7

Please sign in to comment.