Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: "loadPackageData called with empty package path" build panic #60686

Closed
d-enk opened this issue Jun 8, 2023 · 5 comments
Closed

cmd/go: "loadPackageData called with empty package path" build panic #60686

d-enk opened this issue Jun 8, 2023 · 5 comments
Assignees
Labels
GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@d-enk
Copy link

d-enk commented Jun 8, 2023

What version of Go are you using (go version)?

$ go version
go version go1.20.5 linux/amd64

What did you do?

go build

package main

import ""

func main() {}

What did you expect to see?

go 1.19

prog.go:3:8: invalid import path: ""

What did you see instead?

panic: loadPackageData called with empty package path

goroutine 29 [running]:
cmd/go/internal/load.loadPackageData({0xb45d70, 0xc00019a000}, {0xc000028e0e, 0x0}, {0xc00019a938, 0x4}, {0xc00033bf20, 0x1f}, {0xc000032064, 0x1f}, ...)
        /home/linuxbrew/.linuxbrew/Cellar/go/1.20.5/libexec/src/cmd/go/internal/load/pkg.go:815 +0x65d
cmd/go/internal/load.(*preload).preloadImports.func1({0xc000028e0e?, 0x0?})
        /home/linuxbrew/.linuxbrew/Cellar/go/1.20.5/libexec/src/cmd/go/internal/load/pkg.go:1076 +0xa5
created by cmd/go/internal/load.(*preload).preloadImports
        /home/linuxbrew/.linuxbrew/Cellar/go/1.20.5/libexec/src/cmd/go/internal/load/pkg.go:1075 +0x2aa
@dr2chase
Copy link
Contributor

dr2chase commented Jun 9, 2023

@bcmills I fear this is another one for you to look at.

@dr2chase dr2chase added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 9, 2023
@bcmills bcmills added the GoCommand cmd/go label Jun 9, 2023
@matloob
Copy link
Contributor

matloob commented Jun 10, 2023

https://go-review.git.corp.google.com/c/go/+/424855 removed the check that (among other things) the import path was not empty. Before that, the file would have a parse error returned, go/build would move it to InvalidGoFiles, and the loader would ignore it. Now it's treated as a valid go file, we try to load the import and panic because the path is empty.

I'll try to get a fix on monday.

@matloob matloob self-assigned this Jun 10, 2023
@gopherbot
Copy link

Change https://go.dev/cl/502615 mentions this issue: go/build: check for invalid import paths again

@gopherbot
Copy link

Change https://go.dev/cl/502697 mentions this issue: go/build: check for invalid import paths again

@gopherbot
Copy link

Change https://go.dev/cl/502697 mentions this issue: [release-branch.go1.20] go/build: check for invalid import paths again

gopherbot pushed a commit that referenced this issue Jun 13, 2023
The go parser previously checked for invalid import paths, go/build,
seeing the parse error would put files with invalid import paths into
InvalidGoFiles. golang.org/cl/424855 removed that check from the
parser, which meant files with invalid import paths not have any parse
errors on them and not be put into InvalidGoFiles. Do a check for
invalid import paths in go/build soon after parsing so we can make
sure files with invalid import paths go into InvalidGoFiles.

This fixes an issue where the Go command assumed that if a file wasn't
invalid it had non empty import paths, leading to a panic.

Fixes #60754
Updates #60230
Updates #60686

Change-Id: I33c1dc9304649536834939cef7c689940236ee20
Reviewed-on: https://go-review.googlesource.com/c/go/+/502615
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
(cherry picked from commit 962753b)
Reviewed-on: https://go-review.googlesource.com/c/go/+/502697
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jun 20, 2023
@dmitshur dmitshur added this to the Go1.21 milestone Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants