Skip to content

Commit eb8902e

Browse files
authored
fix: Fetching go stdlib without configs (#4655)
This fixes a panics, when go std lib is queried, without a version identifier. This actually had a test case, but it was wired up incorrectly.
1 parent 1349a52 commit eb8902e

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

pkg/frontend/vcs/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ type FileSpec struct {
173173
// FindMapping finds a mapping configuration that matches the given FileSpec
174174
// Returns nil if no matching mapping is found
175175
func (c *PyroscopeConfig) FindMapping(file FileSpec) *MappingConfig {
176+
if c == nil {
177+
return nil
178+
}
179+
176180
// Find the longest matching prefix
177181
var bestMatch *MappingConfig
178182
var bestMatchLen = -1

pkg/frontend/vcs/source/find_go.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (ff FileFinder) fetchGoStdlib(ctx context.Context, path string, version str
8181
defer sp.Finish()
8282

8383
// if there is no version detected, use the one from .pyroscope.yaml
84-
if version == "" {
84+
if version == "" && ff.config != nil {
8585
mapping := ff.config.FindMapping(config.FileSpec{Path: "$GOROOT/src"})
8686
if mapping != nil {
8787
return ff.fetchMappingFile(ctx, mapping, path)

pkg/frontend/vcs/source/find_test.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -414,15 +414,18 @@ require (
414414
mockClient := newMockVCSClient()
415415

416416
// Populate pyroscopeYAML content into first mock file (if present)
417-
mockFiles := append(tt.mockFiles, mockFileResponse{
418-
request: client.FileRequest{
419-
Owner: tt.owner,
420-
Repo: tt.repo,
421-
Ref: tt.ref,
422-
Path: filepath.Join(tt.rootPath, ".pyroscope.yaml"),
423-
},
424-
content: tt.pyroscopeYAML,
425-
})
417+
mockFiles := tt.mockFiles
418+
if tt.pyroscopeYAML != "" {
419+
mockFiles = append(mockFiles, mockFileResponse{
420+
request: client.FileRequest{
421+
Owner: tt.owner,
422+
Repo: tt.repo,
423+
Ref: tt.ref,
424+
Path: filepath.Join(tt.rootPath, ".pyroscope.yaml"),
425+
},
426+
content: tt.pyroscopeYAML,
427+
})
428+
}
426429
mockClient.addFiles(mockFiles...)
427430

428431
// Setup repository URL

0 commit comments

Comments
 (0)