hyperledger/fabric · error

cannot collect files from empty chaincode path

Error message

cannot collect files from empty chaincode path

What it means

Returned by golang platform DescribeCode when the chaincode path argument is an empty string. There is no source location to package or validate, so the guard rejects the request before any filesystem access is attempted.

Source

Thrown at core/chaincode/platforms/golang/platform.go:324

// CodeDescriptor describes the code we're packaging.
type CodeDescriptor struct {
	Source       string // absolute path of the source to package
	MetadataRoot string // absolute path META-INF
	Path         string // import path of the package
	Module       bool   // does this represent a go module
}

func (cd CodeDescriptor) isMetadata(path string) bool {
	return strings.HasPrefix(
		filepath.Clean(path),
		filepath.Clean(cd.MetadataRoot),
	)
}

// DescribeCode returns GOPATH and package information.
func DescribeCode(path string) (*CodeDescriptor, error) {
	if path == "" {
		return nil, errors.New("cannot collect files from empty chaincode path")
	}

	// Use the module root as the source path for go modules
	modInfo, err := moduleInfo(path)
	if err != nil {
		return nil, err
	}

	if modInfo != nil {
		// calculate where the metadata should be relative to module root
		relImport, err := filepath.Rel(modInfo.ModulePath, modInfo.ImportPath)
		if err != nil {
			return nil, err
		}

		return &CodeDescriptor{
			Module:       true,
			MetadataRoot: filepath.Join(modInfo.Dir, relImport, "META-INF"),

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Provide a non-empty chaincode source path in the deployment spec.
  2. Validate path != "" in your client before invoking lifecycle APIs.
  3. Check upstream parsing that may be trimming the path to empty.

Example fix

// before
platform.GetDeploymentPayload("", "")
// after
if ccPath == "" { return errors.New("chaincode path is required") }
payload, err := platform.GetDeploymentPayload(ccPath, "")
Defensive patterns

Strategy: validation

Validate before calling

if ccPath == "" {
	return errors.New("chaincode path must be non-empty")
}

Try / catch

if _, err := golang.DescribeCode(path); err != nil {
	if err.Error() == "cannot collect files from empty chaincode path" {
		// fix the deployment spec's path field
	}
}

Prevention

When it happens

Trigger: Calling DescribeCode("") directly, or ValidatePath/GetDeploymentPayload on a platform whose path resolved to the empty string (e.g. missing or blank chaincode path in the package or install request).

Common situations: Empty 'path' field in chaincode install/instantiate payloads, config defaults not set, stripping a path incorrectly before calling the platform.

Related errors


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