golang/go · error

invalid %s path: %v

Error message

invalid %s path: %v

What it means

`go mod edit` argument parsing (`parsePathVersionOptional`): after splitting a `path@version` argument, the path portion fails `module.CheckImportPath`. Import paths must obey Go's rules (no spaces, lowercase alphanumerics, no leading dots, valid runes). `adj` labels which flag the argument is for (e.g. module/require/exclude).

Source

Thrown at src/cmd/go/internal/modcmd/edit.go:382

}

// parsePathVersionOptional parses path[@version], using adj to
// describe any errors.
func parsePathVersionOptional(adj, arg string, allowDirPath bool) (path, version string, err error) {
	if allowDirPath && modfile.IsDirectoryPath(arg) {
		return arg, "", nil
	}
	before, after, found, err := modload.ParsePathVersion(arg)
	if err != nil {
		return "", "", err
	}
	if !found {
		path = arg
	} else {
		path, version = strings.TrimSpace(before), strings.TrimSpace(after)
	}
	if err := module.CheckImportPath(path); err != nil {
		return path, version, fmt.Errorf("invalid %s path: %v", adj, err)
	}
	if path != arg && !allowedVersionArg(version) {
		return path, version, fmt.Errorf("invalid %s version: %q", adj, version)
	}
	return path, version, nil
}

// parseVersionInterval parses a single version like "v1.2.3" or a closed
// interval like "[v1.2.3,v1.4.5]". Note that a single version has the same
// representation as an interval with equal upper and lower bounds: both
// Low and High are set.
func parseVersionInterval(arg string) (modfile.VersionInterval, error) {
	if !strings.HasPrefix(arg, "[") {
		if !allowedVersionArg(arg) {
			return modfile.VersionInterval{}, fmt.Errorf("invalid version: %q", arg)
		}
		return modfile.VersionInterval{Low: arg, High: arg}, nil
	}

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Correct the import path to match Go's import-path rules (lowercase, alphanumerics, `-`, `_`, `.`, `/`).
  2. Quote shell arguments to avoid whitespace splitting.
  3. Confirm the path against the module's published go.mod `module` directive.

Example fix

// before
go mod edit -require 'foo bar@v1.0.0'

// after
go mod edit -require 'foobar@v1.0.0'
Defensive patterns

Strategy: validation

Validate before calling

// Validate import-path syntax before passing to `go mod edit`.
func validImportPath(p string) error {
    return module.CheckImportPath(p) // import "golang.org/x/mod/module"
}

Prevention

When it happens

Trigger: `go mod edit -require 'foo bar@v1.0.0'` (space in path); `go mod edit -replace 'foo!/bar'` (invalid rune); uppercase-first or leading-dot path.

Common situations: Typos, shell-quoting mistakes, invalid characters pasted from docs, mismatched case expectations.

Related errors


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