Skip to content

Commit 0cc2ffd

Browse files
findleyrgopherbot
authored andcommitted
gopls/internal/cache: fail loudly on command-line-arguments modules
We could do more, but this is a minimal change addressing golang/go#61543. Fixes golang/go#61543 Change-Id: I1535ffcf9246d2d8abad384cab4a29c24696a220 Reviewed-on: https://go-review.googlesource.com/c/tools/+/578455 Auto-Submit: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
1 parent c3c5164 commit 0cc2ffd

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

gopls/internal/cache/load.go

+8
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,14 @@ func (s *Snapshot) load(ctx context.Context, allowNetwork bool, scopes ...loadSc
202202
filterFunc := s.view.filterFunc()
203203
newMetadata := make(map[PackageID]*metadata.Package)
204204
for _, pkg := range pkgs {
205+
if pkg.Module != nil && strings.Contains(pkg.Module.Path, "command-line-arguments") {
206+
// golang/go#61543: modules containing "command-line-arguments" cause
207+
// gopls to get all sorts of confused, because anything containing the
208+
// string "command-line-arguments" is treated as a script. And yes, this
209+
// happened in practice! (https://xkcd.com/327). Rather than try to work
210+
// around this very rare edge case, just fail loudly.
211+
return fmt.Errorf(`load failed: module name in %s contains "command-line-arguments", which is disallowed`, pkg.Module.GoMod)
212+
}
205213
// The Go command returns synthetic list results for module queries that
206214
// encountered module errors.
207215
//
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
This test verifies that we fail loudly if a module name contains
2+
command-line-arguments.
3+
4+
-- flags --
5+
-errors_ok
6+
7+
-- go.mod --
8+
module command-line-arguments //@diag("module", re`command-line-arguments.*disallowed`)
9+
10+
go 1.12
11+
12+
-- x/x.go --
13+
package x //@diag("x", re`command-line-arguments.*disallowed`)

0 commit comments

Comments
 (0)