Skip to content

Commit

Permalink
fix: Unsuccessful context enhancing should not drop frames
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilogorek committed May 30, 2019
1 parent a483786 commit 18c9012
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
22 changes: 10 additions & 12 deletions stacktrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,18 +228,16 @@ func contextifyFrames(frames []Frame) []Frame {
for _, frame := range frames {
lines, initial := sr.readContextLines(frame.AbsPath, frame.Lineno, contextLines)

if lines == nil {
continue
}

for i, line := range lines {
switch {
case i < initial:
frame.PreContext = append(frame.PreContext, string(line))
case i == initial:
frame.ContextLine = string(line)
default:
frame.PostContext = append(frame.PostContext, string(line))
if lines != nil {
for i, line := range lines {
switch {
case i < initial:
frame.PreContext = append(frame.PreContext, string(line))
case i == initial:
frame.ContextLine = string(line)
default:
frame.PostContext = append(frame.PostContext, string(line))
}
}
}

Expand Down
20 changes: 20 additions & 0 deletions stacktrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ func TestStacktraceFrameContext(t *testing.T) {
})
}

func TestStacktraceUnsuccessfulContextifyShouldNotDropFrames(t *testing.T) {
frames := []Frame{{
Function: "fnName",
Module: "same",
Filename: "wat.go",
AbsPath: "this/doesnt/exist/wat.go",
Lineno: 1,
Colno: 2,
}, {
Function: "fnNameFoo",
Module: "sameFoo",
Filename: "foo.go",
AbsPath: "this/doesnt/exist/foo.go",
Lineno: 3,
Colno: 5,
}}
contextifiedFrames := contextifyFrames(frames)
assertEqual(t, len(contextifiedFrames), len(frames))
}

// https://github.com/pkg/errors
func TestExtractStacktracePkgErrors(t *testing.T) {
err := RedPkgErrorsRanger()
Expand Down

0 comments on commit 18c9012

Please sign in to comment.