golang/go · error

%s has malformed module path %q%s at revision %s

Error message

%s has malformed module path %q%s at revision %s

What it means

findDir (coderepo.go:899-901). The root go.mod declares a module path that module.SplitPathVersion cannot parse into prefix + version (returns ok=false). pathMajor is empty (standard module path) so we fall through to the structural validity check, which fails. The declared module path is malformed — missing or non-numeric version segment.

Source

Thrown at src/cmd/go/internal/modfetch/coderepo.go:900

	// Not v2/go.mod, so it's either go.mod or nothing. Which is it?
	if found1 {
		// Explicit go.mod with matching major version ok.
		return rev, r.codeDir, gomod1, nil
	}
	if err1 == nil {
		// Explicit go.mod with non-matching major version disallowed.
		suffix := ""
		if file2 != "" {
			suffix = fmt.Sprintf(" (and ...%s/go.mod does not exist)", r.pathMajor)
		}
		if mpath1 == "" {
			return "", "", nil, fmt.Errorf("%s is missing module path%s at revision %s", file1, suffix, rev)
		}
		if r.pathMajor != "" { // ".v1", ".v2" for gopkg.in
			return "", "", nil, fmt.Errorf("%s has non-...%s module path %q%s at revision %s", file1, r.pathMajor, mpath1, suffix, rev)
		}
		if _, _, ok := module.SplitPathVersion(mpath1); !ok {
			return "", "", nil, fmt.Errorf("%s has malformed module path %q%s at revision %s", file1, mpath1, suffix, rev)
		}
		return "", "", nil, fmt.Errorf("%s has post-%s module path %q%s at revision %s", file1, semver.Major(version), mpath1, suffix, rev)
	}

	if r.codeDir == "" && (r.pathMajor == "" || strings.HasPrefix(r.pathMajor, ".")) {
		// Implicit go.mod at root of repo OK for v0/v1 and for gopkg.in.
		return rev, "", nil, nil
	}

	// Implicit go.mod below root of repo or at v2+ disallowed.
	// Be clear about possibility of using either location for v2+.
	if file2 != "" {
		return "", "", nil, fmt.Errorf("missing %s/go.mod and ...%s/go.mod at revision %s", r.pathPrefix, r.pathMajor, rev)
	}
	return "", "", nil, fmt.Errorf("missing %s/go.mod at revision %s", r.pathPrefix, rev)
}

// isMajor reports whether the versions allowed for mpath are compatible with

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Correct the module path in go.mod to a valid Go module path (e.g. `module example.com/m`).
  2. Run `gofmt`/`go mod tidy` on the source repo to catch malformed go.mod early.
  3. Tag a fixed revision and re-resolve.

Example fix

// before: go.mod
//   module https://example.com/m

// after: go.mod
//   module example.com/m
Defensive patterns

Strategy: validation

Validate before calling

// Validate the module path parses cleanly.
// Go:
package main
import ("fmt"; "golang.org/x/mod/module")
func validatePath(p string) error {
    if _, _, ok := module.SplitPathVersion(p); !ok {
        return fmt.Errorf("malformed module path: %q", p)
    }
    return nil
}
// bash lint:
//   grep -E '^module ' go.mod | grep -vE '^module [a-z0-9./_-]+$' && echo 'suspicious module path'

Prevention

When it happens

Trigger: go.mod's `module` directive is something like `module example.com/m@v2` or `module m` (no dot, unparsable) or any path SplitPathVersion rejects.

Common situations: Typos in the module path (special characters, missing slashes); module paths with invalid version suffixes; paths copy-pasted from URLs including schemes.

Understand the failure class

Related errors


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