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: confusing error message (or incorrect behavior) when using -modfile with go run #51079

Closed
findleyr opened this issue Feb 8, 2022 · 3 comments
Assignees
Labels
modules NeedsInvestigation WaitingForInfo
Milestone

Comments

@findleyr
Copy link
Contributor

@findleyr findleyr commented Feb 8, 2022

I'm experiencing some confusing behavior when trying to use the -modfile flag with go run -- it appears that -modfile is not being honored, though I have not ruled out an error on my side.

Context: in CL 383375, patchset 2, I am trying to use x/tools for the copytermlist.go script (used by go generate), but don't want to add an x/tools dependency to the module. I was planning to manage this additional dependency in a go.tools.mod file.

The -modfile flag appears not to work, even though copying over go.mod and go.sum does work.

> go run -modfile=go.tools.mod copytermlist.go
copytermlist.go:25:2: no required module provides package golang.org/x/tools/go/ast/astutil; to add it:
        go get golang.org/x/tools/go/ast/astutil
> cat go.tools.mod
module golang.org/x/exp/typeparams

go 1.18

require golang.org/x/tools v0.1.9 // indirect
> cp go.tools.mod go.mod && cp go.tools.sum go.sum
> go run copytermlist.go
>

This doesn't match my mental model for how -modfile behaves.

CC @bcmills

@findleyr findleyr added the NeedsInvestigation label Feb 8, 2022
@bcmills bcmills self-assigned this Feb 8, 2022
@bcmills bcmills added the modules label Feb 8, 2022
@bcmills bcmills added this to the Go1.19 milestone Feb 8, 2022
@bcmills
Copy link
Member

@bcmills bcmills commented Feb 16, 2022

I'm not able to reproduce this failure mode from PS2 of that CL.

~/src/golang.org/x/exp/typeparams$ git rev-parse HEAD
ea96774d6baf9befe8eb7b3d5daa01b4aabcd1ae

~/src/golang.org/x/exp/typeparams$ git status
On branch issue51079-modfile
Your branch and 'origin/master' have diverged,
and have 1 and 4 different commits each, respectively.

nothing to commit, working tree clean

~/src/golang.org/x/exp/typeparams$ go1.18beta2 run copytermlist.go
copytermlist.go:25:2: no required module provides package golang.org/x/tools/go/ast/astutil; to add it:
        go get golang.org/x/tools/go/ast/astutil

~/src/golang.org/x/exp/typeparams$ go1.18beta2 run -modfile=go.tools.mod copytermlist.go

~/src/golang.org/x/exp/typeparams$

I'm not sure what to make of that, but at this point I don't have any other ideas about how it might have gone wrong. I did try setting GOFLAGS=-modfile=/dev/null, but the explicit -modfile flag overrode that too.

Is it possible that there was some kind of bad interaction with an IDE overlay, or a delayed file write? (Did you execute the command directly on the command line?)

@bcmills bcmills added the WaitingForInfo label Feb 16, 2022
@gopherbot
Copy link

@gopherbot gopherbot commented Mar 16, 2022

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@findleyr findleyr reopened this Mar 16, 2022
@findleyr findleyr assigned findleyr and unassigned bcmills Mar 16, 2022
@findleyr findleyr reopened this Mar 16, 2022
@findleyr findleyr added WaitingForInfo and removed WaitingForInfo labels Mar 16, 2022
@bcmills bcmills reopened this Apr 18, 2022
@bcmills bcmills reopened this Apr 18, 2022
@bcmills bcmills removed the WaitingForInfo label Apr 18, 2022
@bcmills
Copy link
Member

@bcmills bcmills commented Apr 18, 2022

(I'm just adding this comment to reset the Gopherbot timer. 😅)

@bcmills bcmills added the WaitingForInfo label Apr 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
modules NeedsInvestigation WaitingForInfo
Projects
None yet
Development

No branches or pull requests

3 participants