Check for nil when getting package info

This commit is contained in:
Sauyon Lee
2021-09-02 00:13:54 -07:00
parent 7d3c504c3c
commit f9ce06b4c0
2 changed files with 18 additions and 1 deletions

View File

@@ -148,7 +148,14 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error {
for _, pkg := range pkgs {
info := pkgInfos[pkg.PkgPath]
if info.PkgDir == "" {
if info == nil {
var err error
info, err = util.GetPkgInfo(pkg.PkgPath)
if err != nil {
log.Fatalf("Unable to get a source directory for input package %s: %s", pkg.PkgPath, err)
}
}
if info == nil || info.PkgDir == "" {
log.Fatalf("Unable to get a source directory for input package %s.", pkg.PkgPath)
}
wantedRoots[info.PkgDir] = true

View File

@@ -114,6 +114,16 @@ func GetPkgsInfo(patterns []string, includingDeps bool, flags ...string) (map[st
return pkgInfoMapping, nil
}
// GetPkgsInfo gets the absolute module and package root directories for the package `pkg`, passing
// the internal `go list` command the flags specified by `flags`.
func GetPkgInfo(pkg string, flags ...string) (*PkgInfo, error) {
pkgInfos, err := GetPkgsInfo([]string{pkg}, false, flags...)
if err != nil {
return nil, err
}
return pkgInfos[pkg], nil
}
// DepErrors checks there are any errors resolving dependencies for `pkgpath`. It passes the `go
// list` command the flags specified by `flags`.
func DepErrors(pkgpath string, flags ...string) bool {