golang/go · error
lookup %s: %v
Error message
lookup %s: %v
What it means
This error wraps a failure from codehost.NewRepo — the function that instantiates a VCS-backed repository (git, hg, svn, etc.) for a given module path. If the underlying VCS command fails and the error is not already a *codehost.VCSError, it gets wrapped with the module root path (e.g., 'lookup github.com/example/repo: git clone failed'). VCSErrors pass through unwrapped so they can present richer diagnostics.
Source
Thrown at src/cmd/go/internal/modfetch/repo.go:329
if rr.VCS.Name == "mod" {
// Fetch module from proxy with base URL rr.Repo.
return newProxyRepo(rr.Repo, path)
}
code, err := lookupCodeRepo(ctx, rr, false)
if err != nil {
return nil, err
}
return newCodeRepo(code, rr.Root, rr.SubDir, path)
}
func lookupCodeRepo(ctx context.Context, rr *vcs.RepoRoot, local bool) (codehost.Repo, error) {
code, err := codehost.NewRepo(ctx, rr.VCS.Cmd, rr.Repo, local)
if err != nil {
if _, ok := err.(*codehost.VCSError); ok {
return nil, err
}
return nil, fmt.Errorf("lookup %s: %v", rr.Root, err)
}
return code, nil
}
// A loggingRepo is a wrapper around an underlying Repo
// that prints a log message at the start and end of each call.
// It can be inserted when debugging.
type loggingRepo struct {
r Repo
}
func newLoggingRepo(r Repo) *loggingRepo {
return &loggingRepo{r}
}
// logCall prints a log message using format and args and then
// also returns a function that will print the same message again,
// along with the elapsed time.View on GitHub (pinned to b6b368adc5)
Solutions
- Verify the module path is correct: check the repository URL exists and the module path matches the repository root.
- Ensure the VCS binary (git for most modules) is installed: run 'git version' to confirm.
- Check network connectivity to the VCS host: 'git ls-remote <repo-url>' to reproduce the VCS error directly.
- For private repositories, configure authentication: set GOPRIVATE and ensure git credentials are set up (git config --global credential.helper, SSH keys, or a .netrc file).
- Set GOPROXY to an accessible proxy if direct VCS access is blocked: 'go env -w GOPROXY=https://proxy.golang.org,direct'.
- Examine the wrapped %v error detail — it often contains the exact VCS command output (clone failure, auth error, etc.) which points to the root cause.
Example fix
# before: private repo not accessible $ go get github.com/myorg/private-lib # lookup github.com/myorg/private-lib: git clone ... permission denied # after: configure GOPRIVATE and credentials $ go env -w GOPRIVATE=github.com/myorg/* $ git config --global credential.helper store $ echo 'https://user:token@github.com' >> ~/.git-credentials $ go get github.com/myorg/private-lib
Defensive patterns
Strategy: validation
Validate before calling
// Validate module path and VCS accessibility before go get
func validateModuleVCS(modPath string) error {
// Check if git is available
if _, err := exec.LookPath("git"); err != nil {
return fmt.Errorf("git not found on PATH: %w", err)
}
// For direct mode, verify repo is reachable
repoURL := "https://" + modPath
cmd := exec.Command("git", "ls-remote", repoURL)
return cmd.Run()
} Try / catch
// When wrapping go get, parse for 'lookup' errors to surface VCS issues
if strings.Contains(stderr, "lookup ") && strings.Contains(stderr, ": ") {
// Extract the underlying VCS error
parts := strings.SplitN(stderr, ": ", 3)
if len(parts) == 3 {
vcsErr := parts[2]
// Distinguish auth errors from network errors
if strings.Contains(vcsErr, "permission denied") || strings.Contains(vcsErr, "Authentication failed") {
// suggest credential setup
}
}
} Prevention
- Ensure git (or the relevant VCS) is installed and on PATH
- Set GOPRIVATE for private repositories to use correct credentials
- Pre-validate repo access with 'git ls-remote' in CI
- Cache modules in a local proxy to avoid repeated VCS operations
- Configure GOPROXY with a fallback to direct for resilience
When it happens
Trigger: Produced during module resolution when go needs to fetch source code from a VCS repository directly (GOPROXY=direct or proxy fallback). codehost.NewRepo is called with the VCS command (git, hg, etc.), the repo URL, and a local cache flag. If git clone, hg clone, or the VCS binary itself fails, this wraps the error.
Common situations: The module repository URL is wrong or returns 404 (git clone fails). The VCS binary (git, hg) is not installed or not on PATH. Network connectivity to the VCS host is blocked (firewall, offline environment). The repository requires authentication (private repo, no credentials configured). The repository path contains a typo or the module has been deleted/moved. SSH key or HTTPS credentials are misconfigured for private repos.
Related errors
- reading %s/%s at revision %s: %v
- tls: received empty certificates message
- tls: certificate used with invalid signature algorithm
- tls: invalid signature by the server certificate: {err}
- no explicit url was passed
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/0b7b1f934a73b025.
Report an issue: GitHub.