Skip to content

[telemetry] fix segfault #1569

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

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 6 additions & 6 deletions internal/telemetry/sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func initSentryClient(appName string) bool {
return err == nil
}

func newSentryException(err error) []sentry.Exception {
errMsg := err.Error()
func newSentryException(errToLog error) []sentry.Exception {
errMsg := errToLog.Error()
binPkg := ""
modPath := ""
if build, ok := debug.ReadBuildInfo(); ok {
Expand All @@ -66,12 +66,12 @@ func newSentryException(err error) []sentry.Exception {
var stFunc func() []runtime.Frame
errType := "Generic Error"
for {
if t := exportedErrType(err); t != "" {
if t := exportedErrType(errToLog); t != "" {
errType = t
}

//nolint:errorlint
switch stackErr := err.(type) {
switch stackErr := errToLog.(type) {
// If the error implements the StackTrace method in the redact package, then
// prefer that. The Sentry SDK gets some things wrong when guessing how
// to extract the stack trace.
Expand All @@ -98,11 +98,11 @@ func newSentryException(err error) []sentry.Exception {
return frames
}
}
uw := errors.Unwrap(err)
uw := errors.Unwrap(errToLog)
if uw == nil {
break
}
err = uw
errToLog = uw
}
ex := []sentry.Exception{{Type: errType, Value: errMsg}}
if stFunc != nil {
Expand Down
6 changes: 3 additions & 3 deletions internal/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ func commandEvent(meta Metadata) (id string, msg *segment.Track) {
}

// Error reports an error to the telemetry server.
func Error(err error, meta Metadata) {
if !started || err == nil {
func Error(errToLog error, meta Metadata) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we leave this one as err just to keep the package API clean?

if !started || errToLog == nil {
return
}

Expand All @@ -127,7 +127,7 @@ func Error(err error, meta Metadata) {
EventID: sentry.EventID(ExecutionID),
Level: sentry.LevelError,
User: sentry.User{ID: deviceID},
Exception: newSentryException(redact.Error(err)),
Exception: newSentryException(redact.Error(errToLog)),
Contexts: map[string]map[string]any{
"os": {
"name": build.OS(),
Expand Down