golang/go · error

invalid module version syntax %q

Error message

invalid module version syntax %q

What it means

This error is thrown during query parsing in newQuery when ParsePathVersion finds an '@' separator (found=true) but the version portion either contains another '@' or is empty. For example, 'module@@1.0' has two @ signs, and 'module@' has an empty version. Both indicate malformed module version syntax.

Source

Thrown at src/cmd/go/internal/modget/query.go:148

	// unlike the modules in pkgMods, this module does not inherently exclude
	// any other module in pkgMods.
	mod module.Version

	err error
}

// errSet returns a pathSet containing the given error.
func errSet(err error) pathSet { return pathSet{err: err} }

// newQuery returns a new query parsed from the raw argument,
// which must be either path or path@version.
func newQuery(ld *modload.Loader, raw string) (*query, error) {
	pattern, rawVers, found, err := modload.ParsePathVersion(raw)
	if err != nil {
		return nil, err
	}
	if found && (strings.Contains(rawVers, "@") || rawVers == "") {
		return nil, fmt.Errorf("invalid module version syntax %q", raw)
	}

	// If no version suffix is specified, assume @upgrade.
	// If -u=patch was specified, assume @patch instead.
	version := rawVers
	if version == "" {
		if getU.version == "" {
			version = "upgrade"
		} else {
			version = getU.version
		}
	}

	q := &query{
		raw:            raw,
		rawVersion:     rawVers,
		pattern:        pattern,
		patternIsLocal: filepath.IsAbs(pattern) || search.IsRelativePath(pattern),

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Remove the trailing @ or specify a version: 'go get example.com/mymodule' or 'go get example.com/mymodule@latest'.
  2. Ensure there's exactly one @ separator: 'go get example.com/mymodule@v1.2.0'.
  3. Check scripts that construct go get arguments: ensure the version variable is non-empty before appending @version.
  4. Use valid version keywords: 'go get example.com/mymodule@latest', '@upgrade', '@patch', or '@none'.

Example fix

# before
$ go get example.com/mymodule@
# invalid module version syntax "example.com/mymodule@"

# after
$ go get example.com/mymodule@latest
# or without version (defaults to @upgrade)
$ go get example.com/mymodule
Defensive patterns

Strategy: validation

Validate before calling

// Validate go get argument syntax before passing to go
func validateGetArgSyntax(arg string) error {
    atIdx := strings.Index(arg, "@")
    if atIdx == -1 { return nil } // no @, fine
    if atIdx == len(arg)-1 {
        return fmt.Errorf("argument %q has trailing @ with no version", arg)
    }
    versionPart := arg[atIdx+1:]
    if strings.Contains(versionPart, "@") {
        return fmt.Errorf("argument %q contains multiple @ signs", arg)
    }
    return nil
}

Try / catch

if strings.Contains(stderr, "invalid module version syntax") {
    // Malformed @version in the argument
    // Suggest: check for trailing @ or double @@
}

Prevention

When it happens

Trigger: Parsing a 'go get' argument with the pattern path@version. ParsePathVersion splits on the first '@', returning the version suffix. If that suffix is empty (trailing @ with nothing after) or contains another @ (multiple @ signs), the syntax is invalid.

Common situations: A user types 'go get example.com/mymodule@' (trailing @ with no version). A user types 'go get example.com/mymodule@@v1.0' (double @). A script or CI pipeline constructs the argument incorrectly (e.g., concatenating module path with an empty version variable). A copy-paste error includes an extra @.

Related errors


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