hyperledger/fabric · error

Failed to inject "%s": %s

Error message

Failed to inject "%s": %s

What it means

StreamDockerBuild injects static input files (e.g. .dockercontext entries) into the tar writer via r.PackageWriter.Write. If that write fails, the build context is incomplete, so it aborts with 'Failed to inject <name>'. The wrapped underlying error indicates the actual write problem.

Source

Thrown at core/chaincode/platforms/platforms.go:128

func (r *Registry) StreamDockerBuild(ccType, path string, codePackage io.Reader, inputFiles map[string][]byte, tw *tar.Writer, client dcli.APIClient) error {
	var err error

	// ----------------------------------------------------------------------------------------------------
	// Determine our platform driver from the spec
	// ----------------------------------------------------------------------------------------------------
	platform, ok := r.Platforms[ccType]
	if !ok {
		return fmt.Errorf("could not find platform of type: %s", ccType)
	}

	// ----------------------------------------------------------------------------------------------------
	// First stream out our static inputFiles
	// ----------------------------------------------------------------------------------------------------
	for name, data := range inputFiles {
		err = r.PackageWriter.Write(name, data, tw)
		if err != nil {
			return fmt.Errorf(`Failed to inject "%s": %s`, name, err)
		}
	}

	var (
		goVersion   string
		osVersion   string
		archVersion string
	)
	if ccType == pb.ChaincodeSpec_GOLANG.String() {
		goVersion, osVersion, archVersion, err = util.ParamsImage(client)
		if err != nil {
			return errors.Wrap(err, "get params docker image failed")
		}
	}

	buildOptions, err := platform.DockerBuildOptions(path, goVersion, osVersion, archVersion)
	if err != nil {
		return errors.Wrap(err, "platform failed to create docker build options")

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Inspect the wrapped underlying error for the true write failure and fix it (disk space, memory, permissions).
  2. Retry the chaincode build/install — transient stream failures often clear.
  3. Reduce the size/number of static input files in customized builds.
  4. If running a custom peer, verify the PackageWriter implementation and inputFiles construction.

Example fix

// before (custom input with unreadable data)
inputFiles["Dockerfile"] = nil
// after
inputFiles["Dockerfile"] = []byte(dockerfileContents)
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure all static input files have non-empty byte data before streaming
for (const [name, data] of Object.entries(inputFiles)) {
  if (!Buffer.isBuffer(data) || data.length === 0) throw new Error(`bad input file: ${name}`);
}

Try / catch

try {
  err = streamDockerBuild(ccType, inputFiles, ...)
} catch (err) {
  if (/Failed to inject/.test(err.message)) {
    // fix the named input file / free resources, then retry the build
  }
  throw err
}

Prevention

When it happens

Trigger: GenerateDockerBuild -> StreamDockerBuild looping over inputFiles where PackageWriter.Write(name, data, tw) returns an error — tar write failures, closed/failed writer, or oversized/bad data for a given input file name.

Common situations: System resource limits (disk/memory) during docker build context streaming, corrupted writer state after a previous failed write, or customized inputFiles map containing problematic entries.

Related errors


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