Skip to content

Commit

Permalink
errors/log: be defensive against nil pointer dereference (#650)
Browse files Browse the repository at this point in the history
  • Loading branch information
Integralist authored Sep 30, 2022
1 parent 11902b4 commit df68295
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/errors/log.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package errors

import (
"errors"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -183,10 +184,16 @@ func instrument(l LogEntries, cmd string) {
if v, ok := entry.Caller["LINE"]; ok {
line, _ = v.(int)
}

err := errors.New("unknown").Error()
if entry.Err != nil {
err = entry.Err.Error()
}

// https://docs.sentry.io/product/issues/issue-details/breadcrumbs/
b := sentry.Breadcrumb{
Data: entry.Context,
Message: fmt.Sprintf("%s (file: %s, line: %d)", entry.Err.Error(), file, line),
Message: fmt.Sprintf("%s (file: %s, line: %d)", err, file, line),
Timestamp: entry.Time,
Type: "error",
}
Expand Down

0 comments on commit df68295

Please sign in to comment.