{"record":{"id":"ad2342ace56c56ae","repo":"vitessio/vitess","slug":"malformatted-golang-image-reference-s","errorCode":null,"errorMessage":"malformatted golang image reference: %s","messagePattern":"malformatted golang image reference: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/tools/go-upgrade/go-upgrade.go","lineNumber":493,"sourceCode":"\t\t}\n\n\t\tdigest, err := resolveGolangImageDigest(goVersion, distro)\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\n\t\tdigestsByDistro[distro] = digest\n\t}\n\n\tvar replaceErr error\n\treplaced := golangImageRegexp.ReplaceAllStringFunc(content, func(match string) string {\n\t\tif replaceErr != nil {\n\t\t\treturn match\n\t\t}\n\n\t\tsubmatch := golangImageRegexp.FindStringSubmatch(match)\n\t\tif len(submatch) != 3 {\n\t\t\treplaceErr = fmt.Errorf(\"malformatted golang image reference: %s\", match)\n\t\t\treturn match\n\t\t}\n\n\t\tprefix := submatch[1]\n\t\tdistro := submatch[2]\n\t\tdigest, ok := digestsByDistro[distro]\n\t\tif !ok {\n\t\t\treplaceErr = fmt.Errorf(\"missing golang digest for distro %s\", distro)\n\t\t\treturn match\n\t\t}\n\n\t\treturn fmt.Sprintf(\"%s%s@%s\", prefix, golangDockerTag(goVersion, distro), digest)\n\t})\n\tif replaceErr != nil {\n\t\treturn \"\", replaceErr\n\t}\n\n\treturn replaced, nil","sourceCodeStart":475,"sourceCodeEnd":511,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/tools/go-upgrade/go-upgrade.go#L475-L511","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before (Dockerfile)\nFROM golang:1.22-custombuild\n// after\nFROM golang:1.22-bookworm","handlingStrategy":"validation","validationCode":"re := regexp.MustCompile(`golang:\\d+\\.\\d+(\\.\\d+)?-[a-z0-9]+`)\nfor _, line := range dockerfileLines {\n    if strings.Contains(line, \"golang:\") && !re.MatchString(line) {\n        return fmt.Errorf(\"normalize image line %q to 'golang:<version>-<distro>' before running go-upgrade\", line)\n    }\n}","typeGuard":"func isCanonicalGolangRef(ref string) bool {\n    return golangImageRegexp.MatchString(ref) && len(golangImageRegexp.FindStringSubmatch(ref)) == 3\n}","tryCatchPattern":"if err := upgrade.replaceGolangImageReferences(...); err != nil {\n    if strings.Contains(err.Error(), \"malformatted golang image\") {\n        return fmt.Errorf(\"hand-edited image line detected; restore canonical form: %w\", err)\n    }\n    return err\n}","preventionTips":["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"],"tags":["docker","golang","versioning","ci"],"backgroundTag":"malformed-docker-image-reference","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}