vitessio/vitess · error

malformatted error, got: %v

Error message

malformatted error, got: %v

What it means

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.

Source

Thrown at go/tools/go-upgrade/go-upgrade.go:268

}

// currentGolangVersion gets the running version of Golang in Vitess
// and returns it as a *version.Version.
//
// The root `./go.mod` is the source of truth for the Golang version used by the
// codebase. We read the top-level `go` directive to detect the precise version
// we're using.
func currentGolangVersion() (*version.Version, error) {
	contentRaw, err := os.ReadFile("go.mod")
	if err != nil {
		return nil, err
	}
	content := string(contentRaw)

	versre := regexp.MustCompile(regexpFindGoModGoVersion)
	versionStr := versre.FindStringSubmatch(content)
	if len(versionStr) != 2 {
		return nil, fmt.Errorf("malformatted error, got: %v", versionStr)
	}
	return version.NewVersion(versionStr[1])
}

func currentBootstrapVersion() (bootstrapVersion, error) {
	contentRaw, err := os.ReadFile("Makefile")
	if err != nil {
		return bootstrapVersion{}, err
	}
	content := string(contentRaw)

	versre := regexp.MustCompile(regexpFindBootstrapVersion)
	versionStr := versre.FindStringSubmatch(content)
	if len(versionStr) != 2 {
		return bootstrapVersion{}, fmt.Errorf("malformatted error, got: %v", versionStr)
	}
	_, err = strconv.ParseFloat(versionStr[1], 64)
	if err != nil {

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Open go.mod and confirm there is a valid `go 1.x` directive; add or fix it
  2. Run `go mod tidy` with a modern Go toolchain to normalize go.mod formatting
  3. Check the regexpFindGoModGoVersion regex if the Go language introduced a new directive format the regex doesn't cover
  4. Re-run go-upgrade from the repo root so it reads the correct go.mod

Example fix

// before (go.mod)
module vitess.io/vitess
// missing go directive
// after
module vitess.io/vitess

go 1.22
Defensive patterns

Strategy: validation

Validate before calling

content, _ := os.ReadFile("go.mod")
if !regexp.MustCompile(`(?m)^go \d+\.\d+`).Match(content) {
    return errors.New("go.mod missing valid 'go <major.minor>' directive; run 'go mod tidy' with a modern toolchain")
}

Try / catch

v, err := currentGolangVersion()
if err != nil {
    if strings.Contains(err.Error(), "malformatted") {
        return fmt.Errorf("go.mod has no parseable go directive; run 'go mod tidy': %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01). Data as JSON: /api/errors/b762540aac488c8d. Report an issue: GitHub.