{"record":{"id":"98e55d7ed6fb7541","repo":"golang/go","slug":"error-reading-s-invalid-module-path-q","errorCode":null,"errorMessage":"error reading %s: invalid module path: %q","messagePattern":"error reading (.+?): invalid module path: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modload/modfile.go","lineNumber":72,"sourceCode":"\t\t\t\treturn nil, nil, &gover.TooNewError{What: base.ShortPath(gomod), GoVersion: f.Go.Version, Toolchain: toolchain}\n\t\t\t}\n\t\t}\n\n\t\t// Errors returned by modfile.Parse begin with file:line.\n\t\treturn nil, nil, fmt.Errorf(\"errors parsing %s:\\n%w\", base.ShortPath(gomod), shortPathErrorList(err))\n\t}\n\tif f.Go != nil && gover.Compare(f.Go.Version, gover.Local()) > 0 {\n\t\ttoolchain := \"\"\n\t\tif f.Toolchain != nil {\n\t\t\ttoolchain = f.Toolchain.Name\n\t\t}\n\t\treturn nil, nil, &gover.TooNewError{What: base.ShortPath(gomod), GoVersion: f.Go.Version, Toolchain: toolchain}\n\t}\n\tif f.Module == nil {\n\t\t// No module declaration. Must add module path.\n\t\treturn nil, nil, fmt.Errorf(\"error reading %s: missing module declaration. To specify the module path:\\n\\tgo mod edit -module=example.com/mod\", base.ShortPath(gomod))\n\t} else if err := CheckReservedModulePath(f.Module.Mod.Path); err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"error reading %s: invalid module path: %q\", base.ShortPath(gomod), f.Module.Mod.Path)\n\t}\n\n\treturn data, f, err\n}\n\nfunc shortPathErrorList(err error) error {\n\tif el, ok := errors.AsType[modfile.ErrorList](err); ok {\n\t\tfor i := range el {\n\t\t\tel[i].Filename = base.ShortPath(el[i].Filename)\n\t\t}\n\t}\n\treturn err\n}\n\n// A modFileIndex is an index of data corresponding to a modFile\n// at a specific point in time.\ntype modFileIndex struct {\n\tdata         []byte","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modload/modfile.go#L54-L90","documentation":"Returned by modload.ReadModFile when the module directive is present but CheckReservedModulePath rejects its path — the path uses a reserved segment the toolchain forbids for user modules (e.g. a path element that is a standard-library name or a reserved keyword).","triggerScenarios":"Declaring a module path whose path elements collide with reserved names such as 'std', 'cmd', 'internal', 'builtin', or element names disallowed by module.CheckPath.","commonSituations":"Naming a module 'std', 'cmd', or containing a path component the module-path validator rejects; copying a path that includes a reserved segment.","solutions":["Rename the module path to avoid reserved elements: run 'go mod edit -module=<newpath>' with a valid domain-prefixed path.","Check each path segment against module path rules (no 'std', 'cmd', 'internal' at the root, valid DNS-style first element).","Re-run the failing 'go' command after editing."],"exampleFix":"// before (go.mod)\nmodule std\n// error: error reading go.mod: invalid module path: \"std\"\n\n// after\nmodule example.com/mystd\n$ go mod edit -module=example.com/mystd","handlingStrategy":"validation","validationCode":"// Validate the module path before writing go.mod:\n//   err := module.CheckPath(\"example.com/mymod\")\n//   if err != nil { /* choose a different path */ }\n// Also avoid reserved segments: std, cmd, internal (at root), builtin.","typeGuard":"func isValidModulePath(path string) error {\n    return module.CheckPath(path)\n}","tryCatchPattern":null,"preventionTips":["Use a domain-prefixed path (example.com/...) as the first segment.","Avoid naming any segment 'std', 'cmd', 'builtin', or 'internal' at the root.","Run 'go mod init <path>' rather than hand-writing the module line."],"tags":["go-modules","go-mod","validation","reserved-path"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}