Skip to content

Commit

Permalink
cmd/go/internal/generate: error if failed to find a package
Browse files Browse the repository at this point in the history
Add check for package loader to print error and fail `go generate`
command, if package can not be found.

Fixes golang#60079
  • Loading branch information
g4s8 committed May 13, 2023
1 parent 91b8cc0 commit 4da7dce
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/cmd/go/internal/generate/generate.go
Expand Up @@ -202,6 +202,11 @@ func runGenerate(ctx context.Context, cmd *base.Command, args []string) {
printed := false
pkgOpts := load.PackageOpts{IgnoreImports: true}
for _, pkg := range load.PackagesAndErrors(ctx, pkgOpts, args) {
if pkg.Error != nil {
base.Errorf("%v", pkg.Error)
continue
}

if modload.Enabled() && pkg.Module != nil && !pkg.Module.Main {
if !printed {
fmt.Fprintf(os.Stderr, "go: not generating in packages in dependency modules\n")
Expand All @@ -222,6 +227,7 @@ func runGenerate(ctx context.Context, cmd *base.Command, args []string) {
}
}
}
base.ExitIfErrors()
}

// generate runs the generation directives for a single file.
Expand Down

0 comments on commit 4da7dce

Please sign in to comment.