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