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

confusing error message when combining vendored module dependencies, private GitHub repository, version upgrade, and an expired GitHub Token. #43807

Closed
kalexmills opened this issue Jan 20, 2021 · 1 comment

Comments

@kalexmills
Copy link

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

$ go version
1.15.2

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
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/kalexmills/.cache/go-build"
GOENV="/home/kalexmills/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/kalexmills/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.13"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.13/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/mnt/c/Users/Alex/Sanity/workspace/go-refs-test/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build363522906=/tmp/go-build -gno-record-gcc-switches"

What did you do?

  1. Use a private GitHub repository as a module dependency.
  2. Vendor your dependencies using go mod vendor.
  3. Allow the GitHub access token to expire (or corrupt it locally to mimic an 'expired' token).
  4. Release a new version tag in your private repository
  5. Update the version in go.mod to use the new version tag.
  6. Attempt to build your dependent project (expect complaint about 'unknown revision')
  7. Fix the GitHub access token.
  8. Attempt to build your dependent project (expect dependency to be downloaded).

What did you expect to see?

An error explaining that the GitHub token does not work.

What did you see instead?

[10:12] go-refs-test> go build main.go
go: github.com/kalexmills/private@v1.1.0: reading github.com/kalexmills/private/go.mod at revision v1.1.0: unknown revision v1.1.0

After glancing through the source, I suspect the issue is around line 298 in the below snippet

r.refsOnce.Do(r.loadRefs)
var ref, hash string
if r.refs["refs/tags/"+rev] != "" {
ref = "refs/tags/" + rev
hash = r.refs[ref]
// Keep rev as is: tags are assumed not to change meaning.
} else if r.refs["refs/heads/"+rev] != "" {
ref = "refs/heads/" + rev
hash = r.refs[ref]
rev = hash // Replace rev, because meaning of refs/heads/foo can change.
} else if rev == "HEAD" && r.refs["HEAD"] != "" {
ref = "HEAD"
hash = r.refs[ref]
rev = hash // Replace rev, because meaning of HEAD can change.
} else if len(rev) >= minHashDigits && len(rev) <= 40 && AllHex(rev) {
// At the least, we have a hash prefix we can look up after the fetch below.
// Maybe we can map it to a full hash using the known refs.
prefix := rev
// Check whether rev is prefix of known ref hash.
for k, h := range r.refs {
if strings.HasPrefix(h, prefix) {
if hash != "" && hash != h {
// Hash is an ambiguous hash prefix.
// More information will not change that.
return nil, fmt.Errorf("ambiguous revision %s", rev)
}
if ref == "" || ref > k { // Break ties deterministically when multiple refs point at same hash.
ref = k
}
rev = h
hash = h
}
}
if hash == "" && len(rev) == 40 { // Didn't find a ref, but rev is a full hash.
hash = rev
}
} else {
return nil, &UnknownRevisionError{Rev: rev}
}
If I'm reading it correctly, r.refsErr needs to be checked after line 298. I think instead it's falling through to the else clause at line 335 which is reporting the unknown revision.

I haven't yet attempted a fix, but I am open to doing so.

@seankhliao
Copy link
Member

closing as dup of #25982 , please reopen if you disagree

@golang golang locked and limited conversation to collaborators Jan 20, 2022
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

3 participants