vitessio/vitess · error
malformatted golang image reference: %s
Error message
malformatted golang image reference: %s
What it means
go-upgrade rewrites golang Docker image references in files (e.g. Dockerfiles/workflows) using golangImageRegexp, which expects 3 capture groups (prefix, distro, and the full match context). If a matched image reference doesn't conform to the expected `golang:<tag>` shape, replaceErr is set to this error and the match is left unchanged.
Source
Thrown at go/tools/go-upgrade/go-upgrade.go:493
}
digest, err := resolveGolangImageDigest(goVersion, distro)
if err != nil {
return "", err
}
digestsByDistro[distro] = digest
}
var replaceErr error
replaced := golangImageRegexp.ReplaceAllStringFunc(content, func(match string) string {
if replaceErr != nil {
return match
}
submatch := golangImageRegexp.FindStringSubmatch(match)
if len(submatch) != 3 {
replaceErr = fmt.Errorf("malformatted golang image reference: %s", match)
return match
}
prefix := submatch[1]
distro := submatch[2]
digest, ok := digestsByDistro[distro]
if !ok {
replaceErr = fmt.Errorf("missing golang digest for distro %s", distro)
return match
}
return fmt.Sprintf("%s%s@%s", prefix, golangDockerTag(goVersion, distro), digest)
})
if replaceErr != nil {
return "", replaceErr
}
return replaced, nilView on GitHub (pinned to 01a25a7d17)
Solutions
- Find the file containing the malformed image reference reported by the error and normalize it to the standard `golang:<version>-<distro>` form
- If a new legitimate format exists (new registry/distro), extend golangImageRegexp to capture it
- Avoid hand-editing image lines; let go-upgrade rewrite them
- Re-run go-upgrade to confirm all references are replaced
Example fix
// before (Dockerfile) FROM golang:1.22-custombuild // after FROM golang:1.22-bookworm
Defensive patterns
Strategy: validation
Validate before calling
re := regexp.MustCompile(`golang:\d+\.\d+(\.\d+)?-[a-z0-9]+`)
for _, line := range dockerfileLines {
if strings.Contains(line, "golang:") && !re.MatchString(line) {
return fmt.Errorf("normalize image line %q to 'golang:<version>-<distro>' before running go-upgrade", line)
}
} Type guard
func isCanonicalGolangRef(ref string) bool {
return golangImageRegexp.MatchString(ref) && len(golangImageRegexp.FindStringSubmatch(ref)) == 3
} Try / catch
if err := upgrade.replaceGolangImageReferences(...); err != nil {
if strings.Contains(err.Error(), "malformatted golang image") {
return fmt.Errorf("hand-edited image line detected; restore canonical form: %w", err)
}
return err
} Prevention
- Don't hand-edit golang image lines in Dockerfiles/workflows; let go-upgrade rewrite them
- Keep image references in the canonical golang:<version>-<distro> form
- If a new reference format is legitimate, extend golangImageRegexp with a test
When it happens
Trigger: A file contains a string matched loosely by the image-reference regex but not in the canonical form, e.g. `golang:1.22` with an unexpected suffix, a custom registry form the regex groups differently, or a hand-edited image line like `FROM myrepo/golang:1.22-bookworm-custom` that yields fewer than 3 submatches.
Common situations: Hand-editing a Dockerfile or CI workflow image line; adding a new distro tag format not anticipated by the regex; using a private registry mirror whose reference shape differs from the standard golang image.
Related errors
- missing golang digest for distro %s
- malformatted error, got: %v
- golang version malformatted: %s
- resolve golang digest for %s: %w
- package %s is not under %s
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/ad2342ace56c56ae.
Report an issue: GitHub.