Skip to content

Commit

Permalink
Don't panic on missing pkg.Module
Browse files Browse the repository at this point in the history
  • Loading branch information
podtserkovskiy committed Oct 29, 2024
1 parent 6934633 commit b45635d
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions internal/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,10 @@ func normalizePackage(opts *config.IndexOpts, pkg *packages.Package) *packages.P
// We strip that to standardize all the libraries to make sure we are able to jump-to-definition
// of the standard library.
pkg.PkgPath = strings.TrimPrefix(pkg.PkgPath, "std/")
} else {
if pkg.Module == nil {
panic(fmt.Sprintf(
"Should not be possible to have nil module for userland package: %s %s",
pkg,
pkg.PkgPath,
))
}
}

if pkg.Module == nil {
pkg.Module = &packages.Module{}
}

// Follow replaced modules
Expand Down Expand Up @@ -226,7 +221,16 @@ func normalizePackage(opts *config.IndexOpts, pkg *packages.Package) *packages.P
}

if pkg.Module.Path == "" {
pkg.Module.Path = "."
if opts.ModulePath != "" {
pkg.Module.Path = opts.ModulePath
} else {
log.Errorf(
"Should not be possible to have nil module for userland package: %s %s",
pkg,
pkg.PkgPath,
)
pkg.Module.Path = "."
}
}

if pkg.Module.Version == "" {
Expand Down

0 comments on commit b45635d

Please sign in to comment.