hyperledger/fabric · error

error reading chaincode directory at %s

Error message

error reading chaincode directory at %s

What it means

ListInstalledChaincodes wraps ReadDir failures with 'error reading chaincode directory at %s'. It cannot enumerate the installed packages, so any listing (e.g. _lifecycle QueryInstalledChaincodes) fails.

Source

Thrown at core/chaincode/persistence/persistence.go:228

	return s.ReadWriter.Remove(ccInstallPkgPath)
}

// CodePackageNotFoundErr is the error returned when a code package cannot
// be found in the persistence store
type CodePackageNotFoundErr struct {
	PackageID string
}

func (e CodePackageNotFoundErr) Error() string {
	return fmt.Sprintf("chaincode install package '%s' not found", e.PackageID)
}

// ListInstalledChaincodes returns an array with information about the
// chaincodes installed in the persistence store
func (s *Store) ListInstalledChaincodes() ([]chaincode.InstalledChaincode, error) {
	files, err := s.ReadWriter.ReadDir(s.Path)
	if err != nil {
		return nil, errors.Wrapf(err, "error reading chaincode directory at %s", s.Path)
	}

	installedChaincodes := []chaincode.InstalledChaincode{}
	for _, file := range files {
		if instCC, isInstCC := installedChaincodeFromFilename(file.Name()); isInstCC {
			installedChaincodes = append(installedChaincodes, instCC)
		}
	}
	return installedChaincodes, nil
}

// GetChaincodeInstallPath returns the path where chaincodes
// are installed
func (s *Store) GetChaincodeInstallPath() string {
	return s.Path
}

// PackageID returns the package ID with the label and hash of the chaincode install package

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Recreate the directory with correct ownership (it is normally created by Initialize with 0o750)
  2. Restore correct permissions for the peer user on the chaincodes path
  3. Check the volume/mount is present before starting the peer
  4. Run queryinstalled again after the filesystem is repaired

Example fix

// before
rm -rf lifecycle/chaincodes  (dir gone)
// after
mkdir -p lifecycle/chaincodes && chown peer:peer lifecycle/chaincodes
Defensive patterns

Strategy: validation

Validate before calling

st, err := os.Stat(storePath)
if err != nil { return fmt.Errorf("missing dir: %w", err) }
if !st.IsDir() { return fmt.Errorf("%s is not a directory", storePath) }

Type guard

func dirReadable(p string) bool { st, err := os.Stat(p); return err == nil && st.IsDir() }

Try / catch

ccs, err := store.ListInstalledChaincodes()
if err != nil && strings.Contains(err.Error(), "error reading chaincode directory") {
  os.MkdirAll(storePath, 0o750) // repair then retry
}

Prevention

When it happens

Trigger: Calling ListInstalledChaincodes() when os.ReadDir(s.Path) fails: directory missing (deleted externally), permission denied, or path is not a directory.

Common situations: Admin manually deleted the _lifecycle chaincodes dir; permissions reset by redeploy without volume; mount point not yet mounted so the dir is absent at startup.

Related errors


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