{"record":{"id":"b762540aac488c8d","repo":"vitessio/vitess","slug":"malformatted-error-got-v","errorCode":null,"errorMessage":"malformatted error, got: %v","messagePattern":"malformatted error, got: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/tools/go-upgrade/go-upgrade.go","lineNumber":268,"sourceCode":"}\n\n// currentGolangVersion gets the running version of Golang in Vitess\n// and returns it as a *version.Version.\n//\n// The root `./go.mod` is the source of truth for the Golang version used by the\n// codebase. We read the top-level `go` directive to detect the precise version\n// we're using.\nfunc currentGolangVersion() (*version.Version, error) {\n\tcontentRaw, err := os.ReadFile(\"go.mod\")\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tcontent := string(contentRaw)\n\n\tversre := regexp.MustCompile(regexpFindGoModGoVersion)\n\tversionStr := versre.FindStringSubmatch(content)\n\tif len(versionStr) != 2 {\n\t\treturn nil, fmt.Errorf(\"malformatted error, got: %v\", versionStr)\n\t}\n\treturn version.NewVersion(versionStr[1])\n}\n\nfunc currentBootstrapVersion() (bootstrapVersion, error) {\n\tcontentRaw, err := os.ReadFile(\"Makefile\")\n\tif err != nil {\n\t\treturn bootstrapVersion{}, err\n\t}\n\tcontent := string(contentRaw)\n\n\tversre := regexp.MustCompile(regexpFindBootstrapVersion)\n\tversionStr := versre.FindStringSubmatch(content)\n\tif len(versionStr) != 2 {\n\t\treturn bootstrapVersion{}, fmt.Errorf(\"malformatted error, got: %v\", versionStr)\n\t}\n\t_, err = strconv.ParseFloat(versionStr[1], 64)\n\tif err != nil {","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/tools/go-upgrade/go-upgrade.go#L250-L286","documentation":"go-upgrade reads go.mod and extracts the current `go <version>` directive with a regex expecting exactly two submatch groups (full match + version). If the regex doesn't match (fewer than 2 groups), the content is deemed malformed and this error is returned with the matched slice printed.","triggerScenarios":"Running go-upgrade against a go.mod that has no `go` directive, an unusual format (e.g. `go 1` or extra text on the same line that breaks the regex), or an empty/truncated go.mod.","commonSituations":"Upgrading the module with an old toolchain that rewrote go.mod; a manually edited go.mod with a nonstandard go directive; running the tool in a directory without a go.mod containing a go directive (error message says 'malformatted error' though it's really a missing/invalid go directive — a known confusing message).","solutions":["Open go.mod and confirm there is a valid `go 1.x` directive; add or fix it","Run `go mod tidy` with a modern Go toolchain to normalize go.mod formatting","Check the regexpFindGoModGoVersion regex if the Go language introduced a new directive format the regex doesn't cover","Re-run go-upgrade from the repo root so it reads the correct go.mod"],"exampleFix":"// before (go.mod)\nmodule vitess.io/vitess\n// missing go directive\n// after\nmodule vitess.io/vitess\n\ngo 1.22","handlingStrategy":"validation","validationCode":"content, _ := os.ReadFile(\"go.mod\")\nif !regexp.MustCompile(`(?m)^go \\d+\\.\\d+`).Match(content) {\n    return errors.New(\"go.mod missing valid 'go <major.minor>' directive; run 'go mod tidy' with a modern toolchain\")\n}","typeGuard":null,"tryCatchPattern":"v, err := currentGolangVersion()\nif err != nil {\n    if strings.Contains(err.Error(), \"malformatted\") {\n        return fmt.Errorf(\"go.mod has no parseable go directive; run 'go mod tidy': %w\", err)\n    }\n    return err\n}","preventionTips":["Never hand-edit or remove the go directive in go.mod","Run `go mod tidy` with a current Go toolchain after any toolchain change","Run go-upgrade only from the repository root"],"tags":["golang","go-mod","versioning","tooling"],"backgroundTag":"malformed-go-version-directive","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}