hyperledger/fabric · error

failed to create chaincode package: %s

Error message

failed to create chaincode package: %s

What it means

GetDeploymentPayload walks the project folder and writes files into the tar via util.WriteFolderToTarPackage; if that walk/write fails (unreadable files, I/O errors, excluded-file handling issues), the error is wrapped and surfaced as a package-creation failure.

Source

Thrown at core/chaincode/platforms/java/platform.go:112

		logger.Error("ChaincodeSpec's path cannot be empty")
		return nil, errors.New("ChaincodeSpec's path cannot be empty")
	}

	// trim trailing slash if it exists
	if path[len(path)-1] == '/' {
		path = path[:len(path)-1]
	}

	buf := &bytes.Buffer{}
	gw := gzip.NewWriter(buf)
	tw := tar.NewWriter(gw)

	excludedDirs := []string{"target", "build", "out"}
	excludedFileTypes := map[string]bool{".class": true}
	err := util.WriteFolderToTarPackage(tw, path, excludedDirs, nil, excludedFileTypes)
	if err != nil {
		logger.Errorf("Error writing java project to tar package %s", err)
		return nil, fmt.Errorf("failed to create chaincode package: %s", err)
	}

	tw.Close()
	gw.Close()

	return buf.Bytes(), nil
}

func (p *Platform) GenerateDockerfile() (string, error) {
	var buf []string

	buf = append(buf, "FROM "+util.GetDockerImageFromConfig("chaincode.java.runtime"))
	buf = append(buf, "ADD binpackage.tar /root/chaincode-java/chaincode")

	dockerFileContents := strings.Join(buf, "\n")

	return dockerFileContents, nil
}

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Check read permissions on the chaincode source directory and its files
  2. Verify the path points to an existing directory (the Java project root)
  3. Check available disk/memory since the package is built in a buffer
  4. Re-run packaging; inspect the wrapped cause in the error message for the true failure

Example fix

// before
path := "/opt/chaincode/java/mycc" // directory deleted by CI cleanup
payload, err := platform.GetDeploymentPayload(path)
// after
path := "/opt/chaincode/java/mycc" // ensure it exists and is readable
if _, err := os.Stat(path); err != nil { return nil, err }
payload, err := platform.GetDeploymentPayload(path)
Defensive patterns

Strategy: try-catch

Validate before calling

if fi, err := os.Stat(path); err != nil || !fi.IsDir() { return errors.New("path must be an existing readable directory") }

Try / catch

payload, err := platform.GetDeploymentPayload(path)
if err != nil && strings.Contains(err.Error(), "failed to create chaincode package") {
    // inspect cause; fix fs issue then retry packaging
}

Prevention

When it happens

Trigger: WriteFolderToTarPackage returns an error while traversing the project directory — unreadable file, I/O failure writing to the tar/zip writer, or a wrapped error from walking excluded dirs.

Common situations: The chaincode source directory is unreadable (permissions) or was deleted mid-package; disk full while building the in-memory buffer; the path points to a file rather than a directory; filesystem errors in a containerized build.

Related errors


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