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: go mod tidy on a forked repo fails with unclear error message #35719

Open
moficodes opened this issue Nov 20, 2019 · 7 comments

Comments

@moficodes
Copy link

@moficodes moficodes commented Nov 20, 2019

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

$ go version
go version go1.13.4 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOOS="darwin"

What did you do?

This is I think more of an error message issue than anything else.

Say there is a project I like
https://github.com/manifoldco/promptui for example.
Say I forked it.
https://github.com/moficodes/promptui

And then changed the go.mod file to point to a new module name.

module github.com/moficodes/promptui instead of module github.com/manifoldco/promptui

Now once the code is pushed back to github. Then I want to use it in one my other module project.

What did you expect to see?

Go module to pull the code from the repo.

What did you see instead?

$ go mod tidy
go mod tidy

go: custom_select imports
	github.com/moficodes/promptui: github.com/moficodes/promptui@v0.3.2: parsing go.mod:
	module declares its path as: github.com/manifoldco/promptui
	        but was required as: github.com/moficodes/promptui

Solution

This was happening because the original repo had releases and go mod was pulling that as the latest version although the go.mod in the actual repo was updated. So I just made a new release in my fork and it worked ok.

I think the error message can be little bit clearer if possible. I did not see it until I logged into github in my browser.

Or probably there is a more idiomatic way to solve this issue that I am not aware of. Either way more clarity on this would be useful.

😊

@toothrot toothrot changed the title Go mod on a forked repo fails with unclear error message cmd/go: go mod tidy on a forked repo fails with unclear error message Nov 22, 2019
@toothrot toothrot added this to the Backlog milestone Nov 22, 2019
@toothrot

This comment has been minimized.

Copy link
Contributor

@toothrot toothrot commented Nov 22, 2019

Thanks for reporting this, @moficodes. I took a look at https://github.com/moficodes/promptui, and noticed there was still many files that referenced the old name as an import path: github.com/manifoldco/promptui

	modified:   _examples/confirm/main.go
	modified:   _examples/custom_prompt/main.go
	modified:   _examples/custom_select/main.go
	modified:   _examples/prompt/main.go
	modified:   _examples/prompt_default/main.go
	modified:   _examples/prompt_password/main.go
	modified:   _examples/select/main.go
	modified:   _examples/select_add/main.go
	modified:   select_test.go

Changing those files for me locally resolved the issue. This seems to be in line with the error message you mentioned.

I'm going to /cc @bcmills to verify if there's a better way to clarify that, but I think it makes sense.

@moficodes

This comment has been minimized.

Copy link
Author

@moficodes moficodes commented Nov 25, 2019

I dont think having those reference to the old repo was the problem.

I created a new folder with a new gomod file

go mod init select

added file main.go with code

package main

import (
	"fmt"

	"github.com/moficodes/promptui"
)

func main() {
	prompt := promptui.Prompt{
		Label:     "Delete Resource",
		IsConfirm: true,
	}

	result, err := prompt.Run()

	if err != nil {
		fmt.Printf("Prompt failed %v\n", err)
		return
	}

	fmt.Printf("You choose %q\n", result)
}

ran go mod tidy

got

go: select imports
        github.com/moficodes/promptui: github.com/moficodes/promptui@v0.3.2: parsing go.mod:
        module declares its path as: github.com/manifoldco/promptui
                but was required as: github.com/moficodes/promptui

If I am the only one getting this error then I might have to check my go env setup.

@agnivade

This comment has been minimized.

Copy link
Contributor

@agnivade agnivade commented Nov 26, 2019

Your forked repo still has references to the old package path. I still don't see a change in the current master. Please see @toothrot's message above.

I agree that this is the right error message. But perhaps @bcmills can weigh in if there is anything else that can be done.

@moficodes

This comment has been minimized.

Copy link
Author

@moficodes moficodes commented Nov 26, 2019

@agnivade I got rid of all the reference to the old repo from this repo.

https://github.com/moficodes/promptui

https://github.com/moficodes/promptui/search?q=github.com%2Fmanifoldco%2Fpromptui&unscoped_q=github.com%2Fmanifoldco%2Fpromptui

Still on the new repo getting the same error message. Thought might module might have been cached. So deleted to go/pkg/mod folder just to be sure.

Still

go: finding github.com/moficodes/promptui v0.3.2
go: downloading github.com/moficodes/promptui v0.3.2
go: extracting github.com/moficodes/promptui v0.3.2
go: github.com/moficodes/promptui@v0.3.2: parsing go.mod: unexpected module path "github.com/manifoldco/promptui"
go: error loading module requirements
@agnivade

This comment has been minimized.

Copy link
Contributor

@agnivade agnivade commented Nov 26, 2019

Because it is taking the 0.3.2 release. Not master. Fetch the master branch or cut a new release and let us know if the problem persists.

@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Nov 26, 2019

@toothrot, note that files in the _examples subdirectory should have no effect. Per https://golang.org/cmd/go/#hdr-Package_lists_and_patterns:

Directory and file names that begin with "." or "_" are ignored by the go tool, as are directories named "testdata".

@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Nov 26, 2019

@moficodes, what about the error message is unclear?

The error messages refer to the specific path and version in use (v0.3.2), and the go.mod file in that version does indeed have a mismatched module path (https://github.com/moficodes/promptui/blob/20f2a94120aa14a334121a6de66616a7fa89a5cd/go.mod#L1).

You may also find the error messages a bit clearer using a go command built from head: we've adding a bit more logging when we resolve an import path to a module, which may help clarify why v0.3.2 is being added to your dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.