Skip to content

Commit

Permalink
Return error if adding a package fails.
Browse files Browse the repository at this point in the history
Signed-off-by: Prabhu Rajasekaran <prabhukr@google.com>
  • Loading branch information
Prabhuk committed Jun 8, 2022
1 parent e9f8255 commit a51c167
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/pkg/bb/findpkg/bb.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func loadFSPackages(l ulog.Logger, env golang.Environ, filesystemPaths []string)
return nil, fmt.Errorf("could not find packages in module %s: %v", moduleDir, err)
}
for _, pkg := range pkgs {
allps = addPkg(l, allps, pkg)
allps, err = addPkg(l, allps, pkg)
}
}

Expand All @@ -99,25 +99,24 @@ func loadFSPackages(l ulog.Logger, env golang.Environ, filesystemPaths []string)
return nil, fmt.Errorf("could not find packages: %v", err)
}
for _, p := range vendoredPkgs {
allps = addPkg(l, allps, p)
allps, err = addPkg(l, allps, p)
}
}
return allps, nil
}

func addPkg(l ulog.Logger, plist []*packages.Package, p *packages.Package) []*packages.Package {
func addPkg(l ulog.Logger, plist []*packages.Package, p *packages.Package) ([]*packages.Package, error) {
if len(p.Errors) > 0 {
// TODO(chrisko): should we return an error here instead of warn?
l.Printf("Skipping package %v for errors:", p)
packages.PrintErrors([]*packages.Package{p})
return plist, fmt.Errorf("failed to add package %v for errors:", p)
} else if len(p.GoFiles) == 0 {
l.Printf("Skipping package %v because it has no Go files", p)
} else if p.Name != "main" {
l.Printf("Skipping package %v because it is not a command (must be `package main`)", p)
} else {
plist = append(plist, p)
}
return plist
return plist, nil
}

// NewPackages collects package metadata about all named packages.
Expand All @@ -144,7 +143,7 @@ func NewPackages(l ulog.Logger, env golang.Environ, names ...string) ([]*bbinter
return nil, fmt.Errorf("failed to load package %v: %v", goImportPaths, err)
}
for _, p := range importPkgs {
ps = addPkg(l, ps, p)
ps, err = addPkg(l, ps, p)
}
}

Expand Down

0 comments on commit a51c167

Please sign in to comment.