Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give a better error if package_bindings is a file #221

Merged
merged 2 commits into from
Aug 15, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions generate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"go/token"
"os"
"path/filepath"
"strings"

"golang.org/x/tools/go/packages"
"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -110,6 +111,14 @@ func (c *Config) ValidateAndFillDefaults(baseDir string) error {

if len(c.PackageBindings) > 0 {
for _, binding := range c.PackageBindings {
if strings.HasSuffix(binding.Package, ".go") {
// total heuristic -- but this is an easy mistake to make and
// results in rather bizarre behavior from go/packages.
return errorf(nil,
"package %v looks like a file, but should be a package-name",
binding.Package)
}

mode := packages.NeedImports | packages.NeedTypes | packages.NeedTypesSizes
pkgs, err := packages.Load(&packages.Config{
Mode: mode,
Expand Down