{"record":{"id":"64eabc64c77f8c6f","repo":"golang/go","slug":"malformed-module-path-q","errorCode":null,"errorMessage":"malformed module path %q","messagePattern":"malformed module path %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modload/init.go","lineNumber":1306,"sourceCode":"\t\t\t\t*fixed = true\n\t\t\t}\n\t\t}()\n\n\t\t// Special case: remove the old -gopkgin- hack.\n\t\tif strings.HasPrefix(path, \"gopkg.in/\") && strings.Contains(vers, \"-gopkgin-\") {\n\t\t\tvers = vers[strings.Index(vers, \"-gopkgin-\")+len(\"-gopkgin-\"):]\n\t\t}\n\n\t\t// fixVersion is called speculatively on every\n\t\t// module, version pair from every go.mod file.\n\t\t// Avoid the query if it looks OK.\n\t\t_, pathMajor, ok := module.SplitPathVersion(path)\n\t\tif !ok {\n\t\t\treturn \"\", &module.ModuleError{\n\t\t\t\tPath: path,\n\t\t\t\tErr: &module.InvalidVersionError{\n\t\t\t\t\tVersion: vers,\n\t\t\t\t\tErr:     fmt.Errorf(\"malformed module path %q\", path),\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\t\tif vers != \"\" && module.CanonicalVersion(vers) == vers {\n\t\t\tif err := module.CheckPathMajor(vers, pathMajor); err != nil {\n\t\t\t\treturn \"\", module.VersionError(module.Version{Path: path, Version: vers}, err)\n\t\t\t}\n\t\t\treturn vers, nil\n\t\t}\n\n\t\tinfo, err := Query(ld, ctx, path, vers, \"\", nil)\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t\treturn info.Version, nil\n\t}\n}\n","sourceCodeStart":1288,"sourceCodeEnd":1324,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modload/init.go#L1288-L1324","documentation":"fixVersion (the modfile.VersionFixer used when reading go.mod) was called on a (path, version) pair and module.SplitPathVersion(path) returned !ok, meaning the path itself is structurally malformed. Returned as module.ModuleError wrapping module.InvalidVersionError. This is a speculative fixer so it bails fast on obviously-bad paths.","triggerScenarios":"A require/replace/exclude entry in go.mod references a module whose path SplitPathVersion cannot parse (no domain, illegal characters, malformed version token glued to path). fixVersion returns this ModuleError instead of attempting a Query.","commonSituations":"Hand-edited go.mod with a typo in a require path; a generated/templated go.mod with a bad substitution; a replace target path that violates module path grammar; mixed encoding issues.","solutions":["Inspect go.mod for the offending module path and correct it to a valid domain/path form.","If the entry is stale, remove the require/replace/exclude line.","Run 'go mod tidy' / 'go mod edit' to rewrite the file once the path is valid.","Ensure no control characters or smart-quotes were introduced by copy-paste."],"exampleFix":"// before (go.mod)\nrequire example.com/foo@bad path v1.2.3   // path has a space / bad token\n// fixVersion: malformed module path \"example.com/foo@bad path\"\n\n// after\nrequire example.com/foo v1.2.3","handlingStrategy":"validation","validationCode":"// Pre-validate every module path in go.mod via SplitPathVersion.\ndata, err := os.ReadFile(\"go.mod\")\nif err != nil { return err }\nf, _ := modfile.Parse(\"go.mod\", data, nil)\ncheck := func(path string) error {\n    if _, _, ok := module.SplitPathVersion(path); !ok {\n        return fmt.Errorf(\"malformed module path %q\", path)\n    }\n    return nil\n}\nfor _, r := range f.Require { if e := check(r.Mod.Path); e != nil { return e } }\nfor _, r := range f.Replace { if e := check(r.New.Path); e != nil { return e } }","typeGuard":"func isWellFormedModulePath(p string) bool {\n    _, _, ok := module.SplitPathVersion(p); return ok\n}","tryCatchPattern":"out, err := exec.Command(\"go\", \"build\", \"./...\").CombinedOutput()\nif err != nil && bytes.Contains(out, []byte(\"malformed module path\")) {\n    // surface the offending path from go.mod; do not retry until edited\n    return fmt.Errorf(\"go.mod has a malformed module path; fix require/replace entries: %s\", out)\n}\nreturn err","preventionTips":["Edit module paths only via 'go mod edit' to avoid typos.","Pre-commit: parse go.mod and SplitPathVersion-check each path.","Avoid hand-substituting paths with templating that can inject bad characters.","Re-run 'go mod tidy' after path corrections to validate."],"tags":["go-mod","malformed-path","version-fixer","modfile","validation"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}