Skip to content

Commit 07b3e62

Browse files
author
Bryan C. Mills
committed
cmd/go: report loading errors from 'go mod tidy' and 'go mod vendor'
Fixes #27063 Change-Id: Iedd14fd614a3d79d1387b923a0f123c2bc9e0b33 Reviewed-on: https://go-review.googlesource.com/c/go/+/188763 Run-TryBot: Bryan C. Mills <[email protected]> Reviewed-by: Jay Conrod <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 316ac4f commit 07b3e62

File tree

3 files changed

+43
-8
lines changed

3 files changed

+43
-8
lines changed

src/cmd/go/internal/modload/load.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,11 +387,13 @@ func loadAll(testAll bool) []string {
387387

388388
var paths []string
389389
for _, pkg := range loaded.pkgs {
390-
if e, ok := pkg.err.(*ImportMissingError); ok && e.Module.Path == "" {
391-
continue // Package doesn't actually exist.
390+
if pkg.err != nil {
391+
base.Errorf("%s: %v", pkg.stackText(), pkg.err)
392+
continue
392393
}
393394
paths = append(paths, pkg.path)
394395
}
396+
base.ExitIfErrors()
395397
return paths
396398
}
397399

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
env GO111MODULE=on
2+
3+
# Regression test for golang.org/issue/27063:
4+
# 'go mod tidy' and 'go mod vendor' should not hide loading errors.
5+
6+
! go mod tidy
7+
stderr '^issue27063 imports\n\tnonexist: malformed module path "nonexist": missing dot in first path element'
8+
stderr '^issue27063 imports\n\tnonexist.example.com: cannot find module providing package nonexist.example.com'
9+
stderr '^issue27063 imports\n\tissue27063/other imports\n\tother.example.com/nonexist: cannot find module providing package other.example.com/nonexist'
10+
11+
! go mod vendor
12+
stderr '^issue27063 imports\n\tnonexist: malformed module path "nonexist": missing dot in first path element'
13+
stderr '^issue27063 imports\n\tnonexist.example.com: cannot find module providing package nonexist.example.com'
14+
stderr '^issue27063 imports\n\tissue27063/other imports\n\tother.example.com/nonexist: cannot find module providing package other.example.com/nonexist'
15+
16+
-- go.mod --
17+
module issue27063
18+
19+
go 1.13
20+
21+
require issue27063/other v0.0.0
22+
replace issue27063/other => ./other
23+
-- x.go --
24+
package main
25+
26+
import (
27+
"nonexist"
28+
29+
"nonexist.example.com"
30+
"issue27063/other"
31+
)
32+
33+
func main() {}
34+
-- other/go.mod --
35+
module issue27063/other
36+
-- other/other.go --
37+
package other
38+
39+
import "other.example.com/nonexist"

src/cmd/go/testdata/script/mod_vendor.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,6 @@ package m
171171

172172
import _ "appengine"
173173
import _ "appengine/datastore"
174-
-- nonexistent.go --
175-
// +build alternatereality
176-
177-
package m
178-
179-
import _ "nonexistent.rsc.io"
180174
-- mypkg/go.mod --
181175
module me
182176
-- mypkg/mydir/d.go --

0 commit comments

Comments
 (0)