hyperledger/fabric · error

cannot init crypto, specified path "%s" is not a directory

Error message

cannot init crypto, specified path "%s" is not a directory

What it means

InitCrypto requires mspMgrConfigDir to be a directory containing MSP material. When os.Stat succeeds but fi.IsDir() is false, it returns this error because a file (or symlink to a file) was given where the MSP directory was expected.

Source

Thrown at internal/peer/common/common.go:179

		mapstructure.StringToWeakSliceHookFunc(","),
		factory.StringToKeyIds(),
	))

	if err := subv.Unmarshal(&bccspConfig, opts); err != nil {
		return errors.WithMessage(err, "could not decode peer BCCSP configuration")
	}

	return nil
}

// InitCrypto initializes crypto for this peer
func InitCrypto(mspMgrConfigDir, localMSPID, localMSPType string) error {
	// Check whether msp folder exists
	fi, err := os.Stat(mspMgrConfigDir)
	if err != nil {
		return errors.Errorf("cannot init crypto, specified path \"%s\" does not exist or cannot be accessed: %v", mspMgrConfigDir, err)
	} else if !fi.IsDir() {
		return errors.Errorf("cannot init crypto, specified path \"%s\" is not a directory", mspMgrConfigDir)
	}
	// Check whether localMSPID exists
	if localMSPID == "" {
		return errors.New("the local MSP must have an ID")
	}

	// Init the BCCSP
	bccspConfig := factory.GetDefaultOpts()
	err = InitBCCSPConfig(bccspConfig)
	if err != nil {
		return err
	}

	conf, err := msp.GetLocalMspConfigWithType(mspMgrConfigDir, bccspConfig, localMSPID, localMSPType)
	if err != nil {
		return err
	}
	err = mspmgmt.GetLocalMSP(factory.GetDefault()).Setup(conf)

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Point CORE_PEER_MSPCONFIGPATH at the msp directory itself, not a file inside it.
  2. Verify with: test -d "$CORE_PEER_MSPCONFIGPATH" && echo dir || echo not-a-dir.
  3. Re-extract the MSP archive if the 'msp' path is a leftover file (tar -xzf in the correct location).
  4. For admin operations, keep the admin identity dir separate from the peer's local MSP dir.

Example fix

// before
export CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/msp/admincerts/Admin@org1-cert.pem

// after
export CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/msp
Defensive patterns

Strategy: validation

Validate before calling

mspDir := os.Getenv("CORE_PEER_MSPCONFIGPATH")
fi, err := os.Stat(mspDir)
if err == nil && !fi.IsDir() {
	return fmt.Errorf("%q is a file; CORE_PEER_MSPCONFIGPATH must be the msp directory", mspDir)
}

Try / catch

if err := common.InitCrypto(mspDir, localMSPID, localMSPType); err != nil {
	if strings.Contains(err.Error(), "is not a directory") {
		return fmt.Errorf("CORE_PEER_MSPCONFIGPATH must point at the msp folder, not a file: %w", err)
	}
	return err
}

Prevention

When it happens

Trigger: Calling InitCrypto with mspMgrConfigPath (CORE_PEER_MSPCONFIGPATH or the -o/--file flag) set to a regular file — e.g. pointing at a tarball, a config file, or admincerts file instead of the msp directory.

Common situations: Setting CORE_PEER_MSPCONFIGPATH to an admin signing identity file instead of the MSP folder; pointing at 'msp' where 'msp' is actually a file created by a bad extraction; clipboard/typos pasting a file path rather than directory.

Related errors


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