From: Quan Tong Date: Mon, 6 Nov 2023 05:01:13 +0000 (+0700) Subject: cmd/go: print the package containing the unmatched embed patterns X-Git-Tag: go1.23rc1~1121 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=aa9d2de559c2fff735000e4733b0405652434ff4;p=gostls13.git 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 --- diff --git a/src/cmd/go/internal/modcmd/vendor.go b/src/cmd/go/internal/modcmd/vendor.go index 3db85bda53..44e0439f68 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)) - if err != nil { - base.Fatal(err) - } - if err := os.MkdirAll(filepath.Dir(embedDst), 0777); err != nil { - base.Fatal(err) - } - w, err := os.Create(embedDst) + 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 := 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 1a3b2fef26..4a27b1431f 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