aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cmd/go/internal/modcmd/tidy.go1
-rw-r--r--src/cmd/go/internal/modcmd/vendor.go1
-rw-r--r--src/cmd/go/internal/modload/init.go6
-rw-r--r--src/cmd/go/internal/modload/load.go5
-rw-r--r--src/cmd/go/testdata/script/mod_tidy_error.txt4
5 files changed, 15 insertions, 2 deletions
diff --git a/src/cmd/go/internal/modcmd/tidy.go b/src/cmd/go/internal/modcmd/tidy.go
index af2b04c0c2..5ff847485c 100644
--- a/src/cmd/go/internal/modcmd/tidy.go
+++ b/src/cmd/go/internal/modcmd/tidy.go
@@ -42,6 +42,7 @@ func runTidy(cmd *base.Command, args []string) {
base.Fatalf("go mod tidy: no arguments allowed")
}
+ modload.SilenceMissingStdImports = true
modload.LoadALL()
modload.TidyBuildList()
modTidyGoSum() // updates memory copy; WriteGoMod on next line flushes it out
diff --git a/src/cmd/go/internal/modcmd/vendor.go b/src/cmd/go/internal/modcmd/vendor.go
index 8509ceb7a8..5a5bb943a5 100644
--- a/src/cmd/go/internal/modcmd/vendor.go
+++ b/src/cmd/go/internal/modcmd/vendor.go
@@ -47,6 +47,7 @@ func runVendor(cmd *base.Command, args []string) {
if len(args) != 0 {
base.Fatalf("go mod vendor: vendor takes no arguments")
}
+ modload.SilenceMissingStdImports = true
pkgs := modload.LoadVendor()
vdir := filepath.Join(modload.ModRoot(), "vendor")
diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go
index 664a2a1594..2360feef04 100644
--- a/src/cmd/go/internal/modload/init.go
+++ b/src/cmd/go/internal/modload/init.go
@@ -56,6 +56,12 @@ var (
CmdModModule string // module argument for 'go mod init'
allowMissingModuleImports bool
+
+ // SilenceMissingStdImports indicates that LoadALL should not print an error
+ // or terminate the process if an imported package is missing, and the import
+ // path looks like it might be in the standard library (perhaps in a future
+ // Go version).
+ SilenceMissingStdImports bool
)
// ModFile returns the parsed go.mod file.
diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go
index 30992e0cc2..e5ea1a6c23 100644
--- a/src/cmd/go/internal/modload/load.go
+++ b/src/cmd/go/internal/modload/load.go
@@ -433,6 +433,11 @@ func loadAll(testAll bool) []string {
var paths []string
for _, pkg := range loaded.pkgs {
if pkg.err != nil {
+ if impErr := (*ImportMissingError)(nil); SilenceMissingStdImports &&
+ errors.As(pkg.err, &impErr) &&
+ search.IsStandardImportPath(impErr.Path) {
+ continue
+ }
base.Errorf("%s: %v", pkg.stackText(), pkg.err)
continue
}
diff --git a/src/cmd/go/testdata/script/mod_tidy_error.txt b/src/cmd/go/testdata/script/mod_tidy_error.txt
index b6c24ceaf7..395537b1a7 100644
--- a/src/cmd/go/testdata/script/mod_tidy_error.txt
+++ b/src/cmd/go/testdata/script/mod_tidy_error.txt
@@ -4,12 +4,12 @@ env GO111MODULE=on
# 'go mod tidy' and 'go mod vendor' should not hide loading errors.
! go mod tidy
-stderr '^issue27063 imports\n\tnonexist: package nonexist is not in GOROOT \(.*\)'
+! stderr 'package nonexist is not in GOROOT'
stderr '^issue27063 imports\n\tnonexist.example.com: cannot find module providing package nonexist.example.com'
stderr '^issue27063 imports\n\tissue27063/other imports\n\tother.example.com/nonexist: cannot find module providing package other.example.com/nonexist'
! go mod vendor
-stderr '^issue27063 imports\n\tnonexist: package nonexist is not in GOROOT \(.*\)'
+! stderr 'package nonexist is not in GOROOT'
stderr '^issue27063 imports\n\tnonexist.example.com: cannot find module providing package nonexist.example.com'
stderr '^issue27063 imports\n\tissue27063/other imports\n\tother.example.com/nonexist: cannot find module providing package other.example.com/nonexist'