hyperledger/fabric · error

cannot retrieve package for chaincode %ss, error %s

Error message

cannot retrieve package for chaincode %ss, error %s

What it means

GetChaincodeData looks up a chaincode's ChaincodeData in the CCInfoCache; on a cache miss it fetches the package from the filesystem via cacheSupport.GetChaincode. If that lookup returns an error or a nil package, the cache cannot supply chaincode metadata, so it wraps the underlying error with this message. It signals the chaincode package for the given name:version is missing or unreadable on the peer.

Source

Thrown at core/common/ccprovider/ccinfocache.go:56

		cache:        make(map[string]*ChaincodeData),
		cacheSupport: cs,
	}
}

func (c *ccInfoCacheImpl) GetChaincodeData(ccNameVersion string) (*ChaincodeData, error) {
	// c.cache is guaranteed to be non-nil

	c.RLock()
	ccdata, in := c.cache[ccNameVersion]
	c.RUnlock()

	if !in {

		// the chaincode data is not in the cache
		// try to look it up from the file system
		ccpack, err := c.cacheSupport.GetChaincode(ccNameVersion)
		if err != nil || ccpack == nil {
			return nil, fmt.Errorf("cannot retrieve package for chaincode %ss, error %s", ccNameVersion, err)
		}

		// we have a non-nil ChaincodeData, put it in the cache
		c.Lock()
		ccdata = ccpack.GetChaincodeData()
		c.cache[ccNameVersion] = ccdata
		c.Unlock()
	}

	return ccdata, nil
}

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Install the chaincode package with 'peer chaincode install' so the name:version package exists on the peer
  2. Verify the package file 'name:version' exists in the peer's chaincode install directory and is readable by the peer process
  3. Check the wrapped error (%s suffix) for the root cause — nil err with missing package usually means the package is simply absent
  4. Correct the chaincode name/version string used by the caller

Example fix

// before
ccdata, err := ccprovider.GetChaincodeData("mycc1.0") // typo'd name
// after
ccdata, err := ccprovider.GetChaincodeData("mycc:1.0") // correct name:version
Defensive patterns

Strategy: try-catch

Validate before calling

// Go: check the package exists before touching the cache
nameVer := "mycc:1.0"
if _, err := os.Stat(filepath.Join(installDir, nameVer)); os.IsNotExist(err) {
    return fmt.Errorf("chaincode %s not installed on this peer", nameVer)
}

Type guard

func hasChaincodeData(ccd ccprovider.ChaincodeData) bool { return ccd != nil && ccd.Name != "" }

Try / catch

ccdata, err := ccprovider.GetChaincodeData("mycc:1.0")
if err != nil {
    if strings.Contains(err.Error(), "cannot retrieve package for chaincode") {
        // treat as 'not installed': prompt user to install or fail fast
        return fmt.Errorf("chaincode not installed: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling GetChaincodeData (or TestCCInfoCache) for a 'name:version' that was never installed, was deleted from the peer's chaincode install directory, or whose package file fails ccprovider lookup (corrupt file, permissions, wrong install path).

Common situations: Peer restarted after chaincode files removed from /var/hyperledger/production/chaincodes; chaincode name/version typo in invoke/instantiate; installing under one user and running the peer under another (permission denied); using the cache against a filesystem backing store that was wiped.

Related errors


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