MCPcopy Index your code
hub / github.com/go-errors/errors / sourceLine

Method sourceLine

stackframe.go:73–97  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

71}
72
73func (frame *StackFrame) sourceLine() (string, error) {
74 if frame.LineNumber <= 0 {
75 return "???", nil
76 }
77
78 file, err := os.Open(frame.File)
79 if err != nil {
80 return "", err
81 }
82 defer file.Close()
83
84 scanner := bufio.NewScanner(file)
85 currentLine := 1
86 for scanner.Scan() {
87 if currentLine == frame.LineNumber {
88 return string(bytes.Trim(scanner.Bytes(), " \t")), nil
89 }
90 currentLine++
91 }
92 if err := scanner.Err(); err != nil {
93 return "", err
94 }
95
96 return "???", nil
97}
98
99func packageAndName(fn *runtime.Func) (string, string) {
100 name := fn.Name()

Callers 2

StringMethod · 0.95
SourceLineMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected