Skip to content

Commit 54bed3e

Browse files
committed
cmd/go/internal/load: prevent calling ImportErrorf when the err is *module.InvalidPathError
1. The call of setError is unnecessary bacause setError do nothing when p.Error is not nil. 2. The call of ImportErrorf may panic in this situation (double quotes appear in the import path). Fixes golang#49137
1 parent 8ff254e commit 54bed3e

File tree

1 file changed

+8
-2
lines changed
  • src/cmd/go/internal/load

1 file changed

+8
-2
lines changed

src/cmd/go/internal/load/pkg.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,12 +1844,18 @@ func (p *Package) load(ctx context.Context, opts PackageOpts, path string, stk *
18441844
if other := foldPath[fold]; other == "" {
18451845
foldPath[fold] = p.ImportPath
18461846
} else if other != p.ImportPath {
1847-
setError(ImportErrorf(p.ImportPath, "case-insensitive import collision: %q and %q", p.ImportPath, other))
1847+
var invalidPathErr *module.InvalidPathError
1848+
if !errors.As(err, &invalidPathErr) {
1849+
setError(ImportErrorf(p.ImportPath, "case-insensitive import collision: %q and %q", p.ImportPath, other))
1850+
}
18481851
return
18491852
}
18501853

18511854
if !SafeArg(p.ImportPath) {
1852-
setError(ImportErrorf(p.ImportPath, "invalid import path %q", p.ImportPath))
1855+
var invalidPathErr *module.InvalidPathError
1856+
if !errors.As(err, &invalidPathErr) {
1857+
setError(ImportErrorf(p.ImportPath, "invalid import path %q", p.ImportPath))
1858+
}
18531859
return
18541860
}
18551861

0 commit comments

Comments
 (0)