MCPcopy Create free account
hub / github.com/buggregator/server / enrichFrame

Function enrichFrame

modules/sentry/source_context.go:145–207  ·  view source on GitHub ↗
(fm map[string]any, fetch sourceFetcher, cache map[string]*fetchedSource, missing map[string]bool)

Source from the content-addressed store, hash-verified

143}
144
145func enrichFrame(fm map[string]any, fetch sourceFetcher, cache map[string]*fetchedSource, missing map[string]bool) bool {
146 // Skip frames that already carry source.
147 if s, ok := fm["context_line"].(string); ok && s != "" {
148 return false
149 }
150
151 filename, _ := fm["filename"].(string)
152 if !strings.HasPrefix(filename, "http://") && !strings.HasPrefix(filename, "https://") {
153 return false
154 }
155
156 lineno, ok := toLineNumber(fm["lineno"])
157 if !ok || lineno < 1 {
158 return false
159 }
160 colno, _ := toLineNumber(fm["colno"]) // 1-based, 0 if absent
161
162 src, ok := cache[filename]
163 if !ok {
164 if missing[filename] {
165 return false
166 }
167 text, fetched := fetch(filename)
168 if !fetched {
169 missing[filename] = true
170 return false
171 }
172 src = &fetchedSource{transformed: strings.Split(text, "\n")}
173 if sm, ok := extractSourceMap(text, filename, fetch); ok {
174 src.sm = sm
175 }
176 cache[filename] = src
177 }
178
179 // Prefer the original source via the source map; fall back to the
180 // transformed lines the dev server served.
181 if src.sm != nil {
182 genCol := colno - 1
183 if genCol < 0 {
184 genCol = 0
185 }
186 if srcIdx, origLine, origCol, ok := src.sm.originalPosition(lineno, genCol); ok {
187 if lines, ok := src.sm.originalSourceLines(srcIdx); ok && origLine < len(lines) {
188 applyContext(fm, lines, origLine)
189 // Re-point the frame at the original location. Keep `filename`
190 // (the dev-server URL is the precise path, e.g. .../+page.svelte)
191 // but expose the original name as `abs_path` for reference.
192 fm["lineno"] = origLine + 1
193 fm["colno"] = origCol + 1
194 if name := src.sm.sourceName(srcIdx); name != "" {
195 fm["abs_path"] = name
196 }
197 return true
198 }
199 }
200 }
201
202 if lineno > len(src.transformed) {

Callers 1

enrichStacktraceFunction · 0.85

Calls 6

toLineNumberFunction · 0.85
extractSourceMapFunction · 0.85
applyContextFunction · 0.85
originalPositionMethod · 0.80
originalSourceLinesMethod · 0.80
sourceNameMethod · 0.80

Tested by

no test coverage detected