{"record":{"id":"dc5c10d1b955cc3e","repo":"golang/go","slug":"errors-parsing-s-w","errorCode":null,"errorMessage":"errors parsing %s:\n%w","messagePattern":"errors parsing (.+?):\n%w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modload/modfile.go","lineNumber":59,"sourceCode":"\tif err != nil {\n\t\treturn nil, nil, err\n\t}\n\n\tf, err = modfile.Parse(gomod, data, fix)\n\tif err != nil {\n\t\tf, laxErr := modfile.ParseLax(gomod, data, fix)\n\t\tif laxErr == nil {\n\t\t\tif f.Go != nil && gover.Compare(f.Go.Version, gover.Local()) > 0 {\n\t\t\t\ttoolchain := \"\"\n\t\t\t\tif f.Toolchain != nil {\n\t\t\t\t\ttoolchain = f.Toolchain.Name\n\t\t\t\t}\n\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","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modload/modfile.go#L41-L77","documentation":"Returned by modload.ReadModFile when golang.org/x/mod/modfile.Parse fails on the main module's go.mod. The error list is reformatted with short paths and wrapped. A TooNewError is returned separately only if the lax parse succeeds, so this error specifically means the go.mod is syntactically/semantically invalid even under lax parsing rules — i.e. genuinely malformed.","triggerScenarios":"Any 'go' subcommand that reads the main go.mod when that file contains a directive modfile.Parse rejects: unknown directives, malformed require/replace/exclude syntax, duplicate blocks, invalid quoted strings, or an unparseable go version.","commonSituations":"Hand-editing go.mod and leaving a syntax error; a merge conflict left in go.mod; a tool wrote a non-conformant directive; line endings or stray characters introduced by an editor.","solutions":["Read the file:line prefix in the wrapped error list to find the exact offending line in go.mod.","Run 'go mod edit -print' or 'go mod tidy' to auto-fix trivial formatting issues, or 'go mod edit -fmt' to normalize.","Correct or remove the malformed directive by hand, then re-run the command.","If caused by a merge conflict, resolve the conflict markers in go.mod first."],"exampleFix":"// before (go.mod contains)\nrequire (\n    example.com/pkg v1.2.0\n// missing closing paren\n// error: errors parsing go.mod:\n// \tgo.mod:5: ... \n\n// after\nrequire (\n    example.com/pkg v1.2.0\n)","handlingStrategy":"validation","validationCode":"// Validate go.mod parses before running build steps:\n//   go mod edit -print >/dev/null\n// Non-zero exit means go.mod is malformed; parse errors are printed with file:line.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run 'go mod edit -fmt' to normalize go.mod formatting.","Add a pre-commit hook that runs 'go mod edit -print >/dev/null'.","Never leave merge-conflict markers in go.mod; configure your VCS to flag them."],"tags":["go-modules","go-mod","parse-error","go-modfile"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}