From aa9d2de559c2fff735000e4733b0405652434ff4 Mon Sep 17 00:00:00 2001 From: Quan Tong Date: Mon, 6 Nov 2023 12:01:13 +0700 Subject: [PATCH] cmd/go: print the package containing the unmatched embed patterns Fixes #49534 Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest Change-Id: Ia95868ecc1c3dc9715c0fdc7ab1f30348fffaef5 Reviewed-on: https://go-review.googlesource.com/c/go/+/540017 Auto-Submit: Bryan Mills Reviewed-by: Bryan Mills Reviewed-by: Carlos Amedee LUCI-TryBot-Result: Go LUCI --- src/cmd/go/internal/modcmd/vendor.go | 47 ++++++++++++------- .../go/testdata/script/mod_vendor_embed.txt | 8 +++- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/cmd/go/internal/modcmd/vendor.go b/src/cmd/go/internal/modcmd/vendor.go index 3db85bda530..44e0439f687 100644 --- a/src/cmd/go/internal/modcmd/vendor.go +++ b/src/cmd/go/internal/modcmd/vendor.go @@ -324,7 +324,13 @@ func vendorPkg(vdir, pkg string) { } embeds, err := load.ResolveEmbed(bp.Dir, embedPatterns) if err != nil { - base.Fatal(err) + format := "go: resolving embeds in %s: %v\n" + if vendorE { + fmt.Fprintf(os.Stderr, format, pkg, err) + } else { + base.Errorf(format, pkg, err) + } + return } for _, embed := range embeds { embedDst := filepath.Join(dst, embed) @@ -333,23 +339,30 @@ func vendorPkg(vdir, pkg string) { } // Copy the file as is done by copyDir below. - r, err := os.Open(filepath.Join(src, embed)) + err := func() error { + r, err := os.Open(filepath.Join(src, embed)) + if err != nil { + return err + } + if err := os.MkdirAll(filepath.Dir(embedDst), 0777); err != nil { + return err + } + w, err := os.Create(embedDst) + if err != nil { + return err + } + if _, err := io.Copy(w, r); err != nil { + return err + } + r.Close() + return w.Close() + }() if err != nil { - base.Fatal(err) - } - if err := os.MkdirAll(filepath.Dir(embedDst), 0777); err != nil { - base.Fatal(err) - } - w, err := os.Create(embedDst) - if err != nil { - base.Fatal(err) - } - if _, err := io.Copy(w, r); err != nil { - base.Fatal(err) - } - r.Close() - if err := w.Close(); err != nil { - base.Fatal(err) + if vendorE { + fmt.Fprintf(os.Stderr, "go: %v\n", err) + } else { + base.Error(err) + } } } } diff --git a/src/cmd/go/testdata/script/mod_vendor_embed.txt b/src/cmd/go/testdata/script/mod_vendor_embed.txt index 1a3b2fef26d..4a27b1431fb 100644 --- a/src/cmd/go/testdata/script/mod_vendor_embed.txt +++ b/src/cmd/go/testdata/script/mod_vendor_embed.txt @@ -6,11 +6,15 @@ cmp vendor/example.com/a/subdir/test/xtest/embed.txt a/subdir/test/xtest/embed.t cd broken_no_matching_files ! go mod vendor -stderr 'go: pattern foo.txt: no matching files found' +stderr '^go: resolving embeds in example.com/brokendep: pattern foo.txt: no matching files found$' +go mod vendor -e +stderr '^go: resolving embeds in example.com/brokendep: pattern foo.txt: no matching files found$' cd ../broken_bad_pattern ! go mod vendor -stderr 'go: pattern ../foo.txt: invalid pattern syntax' +stderr '^go: resolving embeds in example.com/brokendep: pattern ../foo.txt: invalid pattern syntax$' +go mod vendor -e +stderr '^go: resolving embeds in example.com/brokendep: pattern ../foo.txt: invalid pattern syntax$' cd ../embed_go122 go mod vendor