golang/go · error

file scheme disallowed

Error message

file scheme disallowed

What it means

validateRepoRoot explicitly rejects the `file:` scheme. Remote module discovery via go-get must not resolve to a local file URL; local modules are handled through replace directives instead.

Source

Thrown at src/cmd/go/internal/vcs/vcs.go:1111

	}
	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" {
		return errors.New("file scheme disallowed")
	}
	return nil
}

var fetchGroup singleflight.Group
var (
	fetchCacheMu sync.Mutex
	fetchCache   = map[string]fetchResult{} // key is metaImportsForPrefix's importPrefix
)

// metaImportsForPrefix takes a package's root import path as declared in a <meta> tag
// and returns its HTML discovery URL and the parsed metaImport lines
// found on the page.
//
// The importPath is of the form "golang.org/x/tools".
// It is an error if no imports are found.
// url will still be valid if err != nil.
// The returned url will be of the form "https://golang.org/x/tools?go-get=1"

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Use an https/git/ssh scheme for the repo root in the meta tag.
  2. For local modules, add a `replace` directive pointing at the local path instead of relying on discovery.

Example fix

// before
<meta name="go-import" content="example.com git file:///modules/lib">

// after (use replace instead)
// go.mod: replace example.com/lib => ../lib
Defensive patterns

Strategy: fallback

Validate before calling

// Block file:// roots in remote discovery; suggest replace.
func rejectFileRoot(root string) error {
    u, err := url.Parse(root)
    if err != nil { return err }
    if u.Scheme == "file" { return errors.New("use a replace directive for local modules") }
    return nil
}

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: A meta tag or import path resolves to a `file://...` repo root during dynamic discovery.

Common situations: Misconfigured vanity tags pointing at file URLs; attempting to treat a local checkout as a remotely-discoverable module.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/8f478db89394815e. Report an issue: GitHub.