Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not log JSON output pipe errors to rollbar. #3568

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also check for io.ErrClosedPipe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, because the error message is "io: read/write on closed pipe" (https://pkg.go.dev/io#pkg-variables). That's not consistent with the rollbar error message we are seeing. I feel like we want to be as narrow as possible right now for this ticket since we're turning off rollbar logging in this case. If we start seeing this, then we can revisit.

if runtime.GOOS == "windows" && errors.Is(err, syscall.Errno(232)) {
// Note: 232 is Windows error code ERROR_NO_DATA, "The pipe is being closed".
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know if the Go library uses error code 109 as well? It is ERROR_BROKEN_PIPE

https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. Regardless, that error message is "The pipe has been ended." As mentioned previously, I think we want to be as narrow as possible right now when turning off rollbar logging. I haven't seen that error message in rollbar yet.

// 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
Loading