Skip to content

Commit 9b66a3f

Browse files
author
Randall C. O'Reilly
committed
a couple of fixes to prevent crashing if package has no files (e.g., go.mod not set properly)
1 parent 5b7e6c3 commit 9b66a3f

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

cmd_build.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ func gopyRunCmdBuild(cmdr *commander.Command, args []string) error {
7474
return fmt.Errorf("gopy-gen: go build / load of package failed with path=%q: %v", path, err)
7575
}
7676
pkg, err := parsePackage(bpkg)
77-
if cfg.Name == "" {
78-
cfg.Name = pkg.Name()
79-
}
8077
if err != nil {
8178
return err
8279
}
80+
if cfg.Name == "" {
81+
cfg.Name = pkg.Name()
82+
}
8383
}
8484
return runBuild("build", cfg)
8585
}

gen.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ func loadPackage(path string, buildFirst bool) (*packages.Package, error) {
122122
}
123123

124124
func parsePackage(bpkg *packages.Package) (*bind.Package, error) {
125+
if len(bpkg.GoFiles) == 0 {
126+
err := fmt.Errorf("gopy: no files in package %q", bpkg.PkgPath)
127+
fmt.Println(err)
128+
return nil, err
129+
}
125130
dir, _ := filepath.Split(bpkg.GoFiles[0])
126131
p := bpkg.Types
127132

0 commit comments

Comments
 (0)