hyperledger/fabric · error

invalid string format: %s

Error message

invalid string format: %s

What it means

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.

Source

Thrown at core/chaincode/platforms/util/utils.go:262

	select {
	case res = <-resWait.Result:
	case err = <-resWait.Error:
		cw.Close()
		return "", "", "", fmt.Errorf("Error waiting for container to complete: %s", err)
	}

	// Wait for stream copying to complete before accessing stdout.
	defer cw.Close()
	buff, _ := io.ReadAll(cw.Reader)
	if res.StatusCode > 0 {
		return "", "", "", fmt.Errorf("Error returned from build: %d \"%s\"", res.StatusCode, string(buff))
	}

	re := regexp.MustCompile(`go\s+version\s+go([\d.]+)\s+(\w+)/(\w+)`)

	matches := re.FindStringSubmatch(string(buff))
	if len(matches) != 4 {
		return "", "", "", fmt.Errorf("invalid string format: %s", string(buff))
	}

	goVersion := "v" + matches[1]
	os := matches[2]
	arch := matches[3]

	return goVersion, os, arch, nil
}

// GetDockerImageFromConfig replaces variables in the config
func GetDockerImageFromConfig(path string) string {
	r := strings.NewReplacer(
		"$(ARCH)", runtime.GOARCH,
		"$(PROJECT_VERSION)", metadata.Version,
		"$(TWO_DIGIT_VERSION)", twoDigitVersion(metadata.Version),
		"$(DOCKER_NS)", metadata.DockerNamespace,
	)

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. 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
  2. Run the image manually (`docker run --rm <image> go version`) to inspect the actual output
  3. Switch to an official golang Docker image that emits the standard version string
  4. If using a custom toolchain, ensure it reports a standard version via `go version` or adjust to a supported image

Example fix

// before: custom devel toolchain whose output does not match
FROM myorg/go-custom:devel
// after: use an official image with standard version output
FROM golang:1.21
// go version -> "go version go1.21.0 linux/amd64" (matches the regex)
Defensive patterns

Strategy: validation

Validate before calling

// confirm the image's go version output matches the expected format before calling ParamsImage
out, _ := exec.Command("docker", "run", "--rm", image, "go", "version").Output()
re := regexp.MustCompile(`go\s+version\s+go([\d.]+)\s+(\w+)/(\w+)`)
if !re.Match(out) {
    return fmt.Errorf("image %s produces unparseable go version output: %s", image, out)
}

Try / catch

// surface the raw output for diagnosis
if err != nil && strings.Contains(err.Error(), "invalid string format") {
    log.Printf("unparseable 'go version' output: %v", err) // error embeds the buffer
    return err
}

Prevention

When it happens

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

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

Related errors


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/20631c673a4a0719. Report an issue: GitHub.