{"record":{"id":"20631c673a4a0719","repo":"hyperledger/fabric","slug":"invalid-string-format-s","errorCode":null,"errorMessage":"invalid string format: %s","messagePattern":"invalid string format: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/platforms/util/utils.go","lineNumber":262,"sourceCode":"\tselect {\n\tcase res = <-resWait.Result:\n\tcase err = <-resWait.Error:\n\t\tcw.Close()\n\t\treturn \"\", \"\", \"\", fmt.Errorf(\"Error waiting for container to complete: %s\", err)\n\t}\n\n\t// Wait for stream copying to complete before accessing stdout.\n\tdefer cw.Close()\n\tbuff, _ := io.ReadAll(cw.Reader)\n\tif res.StatusCode > 0 {\n\t\treturn \"\", \"\", \"\", fmt.Errorf(\"Error returned from build: %d \\\"%s\\\"\", res.StatusCode, string(buff))\n\t}\n\n\tre := regexp.MustCompile(`go\\s+version\\s+go([\\d.]+)\\s+(\\w+)/(\\w+)`)\n\n\tmatches := re.FindStringSubmatch(string(buff))\n\tif len(matches) != 4 {\n\t\treturn \"\", \"\", \"\", fmt.Errorf(\"invalid string format: %s\", string(buff))\n\t}\n\n\tgoVersion := \"v\" + matches[1]\n\tos := matches[2]\n\tarch := matches[3]\n\n\treturn goVersion, os, arch, nil\n}\n\n// GetDockerImageFromConfig replaces variables in the config\nfunc GetDockerImageFromConfig(path string) string {\n\tr := strings.NewReplacer(\n\t\t\"$(ARCH)\", runtime.GOARCH,\n\t\t\"$(PROJECT_VERSION)\", metadata.Version,\n\t\t\"$(TWO_DIGIT_VERSION)\", twoDigitVersion(metadata.Version),\n\t\t\"$(DOCKER_NS)\", metadata.DockerNamespace,\n\t)\n","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/platforms/util/utils.go#L244-L280","documentation":"Thrown by ParamsImage when the container succeeds (exit code 0) but the captured 'go version' output does not match the expected pattern `go version go<major.minor...> <os>/<arch>` (regex expects 4 submatches). The library parses the output to derive the Go version, OS and architecture, and throws this error when parsing fails.","triggerScenarios":"The image's `go version` output format differs from the expected regex - e.g. output is empty, Go is built with custom version strings, the output contains extra text like 'go version devel ...', or locale/module noise is prepended; stderr messages are mixed into the captured output.","commonSituations":"Using a development or custom-built Go toolchain image whose version string doesn't match 'goX.Y os/arch'; an image where `go` is a wrapper script printing extra lines; newer Go releases changing version output format (e.g. RC strings); attaching both stdout and stderr so warnings pollute the buffer.","solutions":["Print/log the captured output (it is included in the error message) and compare it with the expected 'go version goX.Y.Z os/arch' format","Run the image manually (`docker run --rm <image> go version`) to inspect the actual output","Switch to an official golang Docker image that emits the standard version string","If using a custom toolchain, ensure it reports a standard version via `go version` or adjust to a supported image"],"exampleFix":"// before: custom devel toolchain whose output does not match\nFROM myorg/go-custom:devel\n// after: use an official image with standard version output\nFROM golang:1.21\n// go version -> \"go version go1.21.0 linux/amd64\" (matches the regex)","handlingStrategy":"validation","validationCode":"// confirm the image's go version output matches the expected format before calling ParamsImage\nout, _ := exec.Command(\"docker\", \"run\", \"--rm\", image, \"go\", \"version\").Output()\nre := regexp.MustCompile(`go\\s+version\\s+go([\\d.]+)\\s+(\\w+)/(\\w+)`)\nif !re.Match(out) {\n    return fmt.Errorf(\"image %s produces unparseable go version output: %s\", image, out)\n}","typeGuard":null,"tryCatchPattern":"// surface the raw output for diagnosis\nif err != nil && strings.Contains(err.Error(), \"invalid string format\") {\n    log.Printf(\"unparseable 'go version' output: %v\", err) // error embeds the buffer\n    return err\n}","preventionTips":["Use official golang images that emit standard 'go version goX.Y.Z os/arch' output","Avoid devel/custom-built Go toolchains in build images","Keep the Dockerfile free of scripts that add noise to go output","Test the full ParamsImage flow after any Go version upgrade"],"tags":["docker","parse-error","go-version","regex"],"backgroundTag":"output-format-parse-failed","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}