Skip to content

Commit 8bf2b65

Browse files
findleyrgopherbot
authored andcommitted
gopls/internal/cache: add more debugging for golang/go#64235
After several hours of attempts, I am yet again unable to reproduce golang/go#64235. Add additional filtering of bug reports to try to narrow down potential root causes. For golang/go#64235 Change-Id: I30abd08f01ebea221a2ff13bceb4823ae3ac470a Reviewed-on: https://go-review.googlesource.com/c/tools/+/643778 Reviewed-by: Alan Donovan <[email protected]> Auto-Submit: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 7479e1b commit 8bf2b65

File tree

1 file changed

+53
-3
lines changed

1 file changed

+53
-3
lines changed

gopls/internal/cache/check.go

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,59 @@ func (b *typeCheckBatch) importPackage(ctx context.Context, mp *metadata.Package
492492
return bug.Errorf("internal error: package name is %q, want %q (id=%q, path=%q) (see issue #60904) (using GOPACKAGESDRIVER)",
493493
pkg.Name(), item.Name, id, item.Path)
494494
} else {
495-
return bug.Errorf("internal error: package name is %q, want %q (id=%q, path=%q) (see issue #60904)",
496-
pkg.Name(), item.Name, id, item.Path)
497-
495+
// There's a package in the export data with the same path as the
496+
// imported package, but a different name.
497+
//
498+
// This is observed to occur (very frequently!) in telemetry, yet
499+
// we don't yet have a plausible explanation: any self import or
500+
// circular import should have resulted in a broken import, which
501+
// can't be referenced by export data. (Any type qualified by the
502+
// broken import name will be invalid.)
503+
//
504+
// However, there are some mechanisms that could potentially be
505+
// involved:
506+
// 1. go/types will synthesize package names based on the import
507+
// path for fake packages (but as mentioned above, I don't think
508+
// these can be referenced by export data.)
509+
// 2. Test variants have the same path as non-test variant. Could
510+
// that somehow be involved? (I don't see how, particularly using
511+
// the go list driver, but nevertheless it's worth considering.)
512+
// 3. Command-line arguments and main packages may have special
513+
// handling that we don't fully understand.
514+
// Try to sort these potential causes into unique stacks, as well
515+
// as a few other pathological scenarios.
516+
report := func() error {
517+
return bug.Errorf("internal error: package name is %q, want %q (id=%q, path=%q) (see issue #60904)",
518+
pkg.Name(), item.Name, id, item.Path)
519+
}
520+
impliedName := ""
521+
if i := strings.LastIndex(item.Path, "/"); i >= 0 {
522+
impliedName = item.Path[i+1:]
523+
}
524+
switch {
525+
case pkg.Name() == "":
526+
return report()
527+
case item.Name == "":
528+
return report()
529+
case metadata.IsCommandLineArguments(mp.ID):
530+
return report()
531+
case mp.ForTest != "":
532+
return report()
533+
case len(mp.CompiledGoFiles) == 0:
534+
return report()
535+
case len(mp.Errors) > 0:
536+
return report()
537+
case impliedName != "" && impliedName != string(mp.Name):
538+
return report()
539+
case len(mp.CompiledGoFiles) != len(mp.GoFiles):
540+
return report()
541+
case mp.Module == nil:
542+
return report()
543+
case mp.Name == "main":
544+
return report()
545+
default:
546+
return report()
547+
}
498548
}
499549
}
500550
} else {

0 commit comments

Comments
 (0)