-
Notifications
You must be signed in to change notification settings - Fork 13
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(232)) { | ||
// Note: 232 is Windows error code ERROR_NO_DATA, "The pipe is being closed". | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we know if the Go library uses error code https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499- There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment.
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
?There was a problem hiding this comment.
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.