Skip to content

Commit f9ce06b

Browse files
author
Sauyon Lee
committed
Check for nil when getting package info
1 parent 7d3c504 commit f9ce06b

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

extractor/extractor.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,14 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error {
148148

149149
for _, pkg := range pkgs {
150150
info := pkgInfos[pkg.PkgPath]
151-
if info.PkgDir == "" {
151+
if info == nil {
152+
var err error
153+
info, err = util.GetPkgInfo(pkg.PkgPath)
154+
if err != nil {
155+
log.Fatalf("Unable to get a source directory for input package %s: %s", pkg.PkgPath, err)
156+
}
157+
}
158+
if info == nil || info.PkgDir == "" {
152159
log.Fatalf("Unable to get a source directory for input package %s.", pkg.PkgPath)
153160
}
154161
wantedRoots[info.PkgDir] = true

extractor/util/util.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ func GetPkgsInfo(patterns []string, includingDeps bool, flags ...string) (map[st
114114
return pkgInfoMapping, nil
115115
}
116116

117+
// GetPkgsInfo gets the absolute module and package root directories for the package `pkg`, passing
118+
// the internal `go list` command the flags specified by `flags`.
119+
func GetPkgInfo(pkg string, flags ...string) (*PkgInfo, error) {
120+
pkgInfos, err := GetPkgsInfo([]string{pkg}, false, flags...)
121+
if err != nil {
122+
return nil, err
123+
}
124+
return pkgInfos[pkg], nil
125+
}
126+
117127
// DepErrors checks there are any errors resolving dependencies for `pkgpath`. It passes the `go
118128
// list` command the flags specified by `flags`.
119129
func DepErrors(pkgpath string, flags ...string) bool {

0 commit comments

Comments
 (0)