golang/go · error
leading slash
Error message
leading slash
What it means
validateRepoSubDir rejects a repository subdirectory that begins with `/`. Subdirs are expected to be relative paths within the repo; a leading slash would resolve outside the intended tree.
Source
Thrown at src/cmd/go/internal/vcs/vcs.go:1092
rr := &RepoRoot{
Repo: repoURL,
Root: mmi.Prefix,
SubDir: mmi.SubDir,
IsCustom: true,
VCS: vcs,
}
return rr, nil
}
// validateRepoSubDir returns an error if subdir is not a valid subdirectory path.
// We consider a subdirectory path to be valid as long as it doesn't have a leading
// slash (/) or hyphen (-).
func validateRepoSubDir(subdir string) error {
if subdir == "" {
return nil
}
if subdir[0] == '/' {
return errors.New("leading slash")
}
if subdir[0] == '-' {
return errors.New("leading hyphen")
}
return nil
}
// validateRepoRoot returns an error if repoRoot does not seem to be
// a valid URL with scheme.
func validateRepoRoot(repoRoot string) error {
url, err := urlpkg.Parse(repoRoot)
if err != nil {
return err
}
if url.Scheme == "" {
return errors.New("no scheme")
}
if url.Scheme == "file" {View on GitHub (pinned to b6b368adc5)
Solutions
- Fix the meta tag / vanity server to emit a relative subdir (no leading slash).
- Drop the subdir component entirely if the repo root is correct.
Example fix
<!-- before --> <meta name="go-import" content="example.com/git /sub/pkg git+ssh://..."> <!-- after --> <meta name="go-import" content="example.com git+ssh://...">
Defensive patterns
Strategy: validation
Validate before calling
// Validate a vanity subdir before publishing meta tags.
func validSubdir(s string) error {
if strings.HasPrefix(s, "/") { return errors.New("subdir must be relative") }
return nil
} Type guard
null
Try / catch
null
Prevention
- Emit relative subdirs in go-import/go-source meta tags.
- Test vanity paths with `go get -v` after deploying tags.
When it happens
Trigger: A vanity-import meta tag (or VCS path config) supplies a subdir like `/cmd/foo` instead of `cmd/foo`.
Common situations: Misconfigured `<meta name="go-import">`/`go-source` tags; hand-written vanity servers.
Related errors
- no scheme
- file scheme disallowed
- import path does not begin with hostname
- leading hyphen
- value is neither 'auto' nor a valid bool
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/47e8693323cb994a.
Report an issue: GitHub.