• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kinbiko / rogerr / 16694318030

02 Aug 2025 01:55PM UTC coverage: 94.4% (+3.2%) from 91.228%
16694318030

Pull #11

github

kinbiko
refactor: pull out independent code into separate files
Pull Request #11: Implement stacktrace support

76 of 78 new or added lines in 3 files covered. (97.44%)

118 of 125 relevant lines covered (94.4%)

46.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.45
/stacktrace.go
1
package rogerr
2

3
import (
4
        "runtime"
5
        "runtime/debug"
6
        "strings"
7
)
8

9
// Frame represents a single frame in a stacktrace.
10
type Frame struct {
11
        File     string // Full file path
12
        Line     int    // Line number
13
        Function string // Function or method name
14
        InApp    bool   // true if application code, false if dependency
15
}
16

17
// getModulePath returns the application module path for determining if frames are in-app.
18
func getModulePath() string {
30✔
19
        if bi, ok := debug.ReadBuildInfo(); ok {
60✔
20
                return bi.Main.Path
30✔
21
        }
30✔
NEW
22
        return ""
×
23
}
24

25
// captureStacktrace captures the current call stack, excluding rogerr internal frames.
26
func captureStacktrace(modulePath string) []Frame {
30✔
27
        const maxFrames = 64
30✔
28
        ptrs := [maxFrames]uintptr{}
30✔
29

30✔
30
        // Skip 0 frames as we'll filter manually
30✔
31
        pcs := ptrs[0:runtime.Callers(0, ptrs[:])]
30✔
32

30✔
33
        allFrames := make([]Frame, 0, len(pcs))
30✔
34
        iter := runtime.CallersFrames(pcs)
30✔
35

30✔
36
        for {
246✔
37
                frame, more := iter.Next()
216✔
38
                allFrames = append(allFrames, Frame{
216✔
39
                        File:     frame.File,
216✔
40
                        Line:     frame.Line,
216✔
41
                        Function: frame.Function,
216✔
42
                        InApp:    isInApp(frame.Function, modulePath), // Determine if this is application code
216✔
43
                })
216✔
44

216✔
45
                if !more {
246✔
46
                        break
30✔
47
                }
48
        }
49

50
        // Now filter out rogerr frames, but keep everything after the last rogerr frame
51
        lastRogerrIndex := -1
30✔
52
        for i, frame := range allFrames {
246✔
53
                // Only filter out the main rogerr package, not internal modules
216✔
54
                if strings.HasPrefix(frame.Function, "github.com/kinbiko/rogerr.") {
323✔
55
                        lastRogerrIndex = i
107✔
56
                }
107✔
57
        }
58

59
        // Return frames after the last rogerr frame
60
        if lastRogerrIndex >= 0 && lastRogerrIndex+1 < len(allFrames) {
60✔
61
                return allFrames[lastRogerrIndex+1:]
30✔
62
        }
30✔
63

64
        // If no rogerr frames found, return all frames (shouldn't happen)
NEW
65
        return allFrames
×
66
}
67

68
// isInApp determines if a function belongs to the application or a dependency.
69
func isInApp(function, modulePath string) bool {
223✔
70
        if modulePath == "" {
224✔
71
                return false
1✔
72
        }
1✔
73

74
        // Handle case where the binary is built from a module and function names
75
        // start with "main." - check if the module path contains the current module
76
        if strings.HasPrefix(function, "main.") {
225✔
77
                return true
3✔
78
        }
3✔
79

80
        // Check if function belongs to the app module
81
        return strings.HasPrefix(function, modulePath)
219✔
82
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc