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: module tries to access invalid package parent #28917

Closed
gdamore opened this issue Nov 22, 2018 · 10 comments
Closed

cmd/go: module tries to access invalid package parent #28917

gdamore opened this issue Nov 22, 2018 · 10 comments

Comments

@gdamore
Copy link

gdamore commented Nov 22, 2018

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

% go version
go version go1.11.1 darwin/amd64

Does this issue reproduce with the latest release?

I think this is the latest release?

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/garrett/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/garrett/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/tmp/gptmp/src/pair/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/48/hq3502h10mg0_1t71j3j25wm0000gn/T/go-build377919689=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Tried to set up a go module using my package nanomsg.org/go/mangos/v2

package main

import (
	"nanomsg.org/go/mangos/v2"
)

// trivial example to force the import
func main() {
	println("Sample error: ", mangos.ErrBadAddr.Error())
}

Then I do:

garrett@garretts-mbp{105}% go mod init test
go: creating new go.mod: module test
garrett@garretts-mbp{106}% go build
go: finding nanomsg.org/go/mangos/v2 latest
build test: cannot find module for path nanomsg.org/go/mangos/v2

Note that this builds fine without go mod.

Note that we have a vanity import at nanomsg.org/go/mangos/v2:

garrett@garretts-mbp{108}% curl https://nanomsg.org/go/mangos/v2/
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-us">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">

<!-- Go Imports -->
<meta name="go-import" content="nanomsg.org/go/mangos/v2 git https://github.com/nanomsg/mangos-v2">

<meta name="go-source" content="nanomsg.org/go/mangos/v2 https://github.com/nanomsg/mangos-v2 _ https://github.com/nanomsg/mangos-v2/tree/master{/dir} https://github.com/nanomsg/mangos-v2/blob/master{/dir}{file}#L{line}">

</head>
<body>
<p>
Nothing to see here.
</p>
</body>
</html>

What did you expect to see?

A successful build.

What did you see instead?

Failed build due to

build test: cannot find module for path nanomsg.org/go/mangos/v2

Using go build -v is informative:

Fetching https://nanomsg.org/go/mangos/v2?go-get=1
Parsing meta tags from https://nanomsg.org/go/mangos/v2?go-get=1 (status code 200)
get "nanomsg.org/go/mangos/v2": found meta tag get.metaImport{Prefix:"nanomsg.org/go/mangos/v2", VCS:"git", RepoRoot:"https://github.com/nanomsg/mangos-v2"} at https://nanomsg.org/go/mangos/v2?go-get=1
go: finding nanomsg.org/go/mangos/v2 latest
Fetching https://nanomsg.org/go/mangos?go-get=1
Parsing meta tags from https://nanomsg.org/go/mangos?go-get=1 (status code 200)
Fetching https://nanomsg.org/go?go-get=1
Parsing meta tags from https://nanomsg.org/go?go-get=1 (status code 404)
Fetching https://nanomsg.org?go-get=1
Parsing meta tags from https://nanomsg.org?go-get=1 (status code 200)
build test: cannot find module for path nanomsg.org/go/mangos/v2

It is trying to get the parent path nanomsg.org/go (and also nanomsg.org). We don't publish meta data for go at those URLs -- the nanomsg.org/go/mangos/v2 is the top of the valid go import path, nothing higher in the tree is importable. (We also are careful not to import stuff at higher levels.)

I believe that go is attempting to access things outside of the path intended, and failing as a result. (Note that it is potentially difficult for me to provide go import meta headers at the root of my tree...)

@agnivade
Copy link
Contributor

I believe if you have a vanity import path, and you are using module mode, then that library needs to have a go.mod which matches the vanity path.

I don't see any go.mod in https://github.com/nanomsg/mangos-v2.

But in any case, I will tag some experts @myitcv @bcmills

@myitcv
Copy link
Member

myitcv commented Nov 23, 2018

Exactly as @agnivade said. Not only that, the go.mod will, for a v2 version, need to be declared as the module nanomsg.org/go/mangos/v2.

There is no bug here, so please can I suggest we move any further discussion to one of the other forums (https://github.com/golang/go/wiki/Questions).

@myitcv myitcv closed this as completed Nov 23, 2018
@gdamore
Copy link
Author

gdamore commented Nov 23, 2018 via email

@gdamore
Copy link
Author

gdamore commented Nov 23, 2018

One last note: it would be helpful to have a clearer explanation of this, ideally in a blog post or similar. I went looking around and I didn't find that information originally. It's possible that this is just too new, but I probably won't be the last person who gets stuck on this during the transition. (Alternatively, better diagnostics would have helped immensely; I just got an error message that package couldn't be found, but no indication of why it couldn't be found.

@myitcv
Copy link
Member

myitcv commented Nov 23, 2018

@gdamore - thanks, good feedback.

Which parts of the official docs (https://golang.org/cmd/go/#hdr-Modules__module_versions__and_more) and the wiki (https://github.com/golang/go/wiki/Modules) did you find lacking, or poorly sign-posted?

@gdamore
Copy link
Author

gdamore commented Nov 23, 2018

So the part I found missing was any explanation that a vanity project, or a v2 project, needs to provide a go.mod file to be importable by other module using projects.

It seems like this is a sea change for folks developing projects intended for incorporation into other packages, and so library package developers really need to be aware of go modules and that they need to do work to enable their consumers to use them. (I was taking a "wait and see" approach to modules , because I'm not sure I wanted to adopt them myself yet. But this hurts my downstreams that might wanting to adopt them on a more aggressive schedule.)

@gdamore
Copy link
Author

gdamore commented Dec 1, 2018

I'm still struggling to create a go.mod that works with this package. I think I'm in some kind of weird limbo / edge case area. So I'd really like some help because the documentation doesn't seem to be guiding me.

I have a git repo, github.com/nanomsg/mangos-v2

Pre-modules, the import path for this was "nanomsg.org/go/mangos/v2". I had a vanity statement HTML of this form:

I have a go.mod and go.sum file in the repo that refers to the import path:

module nanomsg.org/go/mangos/v2

require (
// more stuff here ...
)

I have placed a v2.0.0 and v2.0.1 tag (the latest on the change that includes the go.mod file).

This is not working, and I'm thinking that the issue is that my old vanity import included the v2, and is a separate repo (because of breaking API changes).

Right now I don't know how to make this package visible, and I've tried lots of different things.

@myitcv
Copy link
Member

myitcv commented Dec 3, 2018

@gdamore I think there was something missing from your previous post. The following:

Pre-modules, the import path for this was "nanomsg.org/go/mangos/v2". I had a vanity statement HTML of this form:

was followed by another paragraph, as opposed to what I expect was going to be a copy-paste of HTML meta tags or similar?

I'm also unclear what is not working from your perspective at the moment:

$ cd $(mktemp -d)
$ go mod init example.com/blah
go: creating new go.mod: module example.com/blah
$ cat <<EOD >main.go
package main

import (
        "fmt"

        "nanomsg.org/go/mangos/v2"
)

func main() {
        fmt.Println(mangos.OptionRaw)
}
EOD
$ go run .
go: finding nanomsg.org/go/mangos/v2 v2.0.1
go: downloading nanomsg.org/go/mangos/v2 v2.0.1
go: finding golang.org/x/sys v0.0.0-20181128092732-4ed8d59d0b35
go: finding github.com/Microsoft/go-winio v0.4.11
go: finding github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c
go: finding github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e
go: finding github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d
go: finding github.com/jtolds/gls v4.2.1+incompatible
go: finding github.com/gorilla/websocket v1.4.0
go: finding github.com/droundy/goopt v0.0.0-20170604162106-0b8effe182da
RAW

@gdamore
Copy link
Author

gdamore commented Dec 3, 2018

I think I figured this out... I had a blank line in my HTML before the meta tags, which I think caused them not to be processed properly. Removal of the blank line seems to have solved the problem. Apparently Go's HTML processor for these tags is somewhat fragile.

@myitcv
Copy link
Member

myitcv commented Dec 3, 2018

I think I figured this out

Great.

Apparently Go's HTML processor for these tags is somewhat fragile.

Please raise an issue for this if you have a repro.

@golang golang locked and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants