{"record":{"id":"8945ac7c13ed3891","repo":"hyperledger/fabric","slug":"could-not-get-peer-bccsp-configuration","errorCode":null,"errorMessage":"could not get peer BCCSP configuration","messagePattern":"could not get peer BCCSP configuration","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/peer/common/common.go","lineNumber":156,"sourceCode":"\t\tif strings.Contains(fmt.Sprint(err), \"Unsupported Config Type\") {\n\t\t\treturn errors.New(fmt.Sprintf(\"Could not find config file. \"+\n\t\t\t\t\"Please make sure that FABRIC_CFG_PATH is set to a path \"+\n\t\t\t\t\"which contains %s.yaml\", cmdRoot))\n\t\t} else {\n\t\t\treturn errors.WithMessagef(err, \"error when reading %s config file\", cmdRoot)\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// InitBCCSPConfig initializes BCCSP config\nfunc InitBCCSPConfig(bccspConfig *factory.FactoryOpts) error {\n\tSetBCCSPKeystorePath()\n\n\tsubv := viper.Sub(\"peer.BCCSP\")\n\tif subv == nil {\n\t\treturn fmt.Errorf(\"could not get peer BCCSP configuration\")\n\t}\n\n\topts := viper.DecodeHook(mapstructure.ComposeDecodeHookFunc(\n\t\tmapstructure.StringToTimeDurationHookFunc(),\n\t\tmapstructure.StringToWeakSliceHookFunc(\",\"),\n\t\tfactory.StringToKeyIds(),\n\t))\n\n\tif err := subv.Unmarshal(&bccspConfig, opts); err != nil {\n\t\treturn errors.WithMessage(err, \"could not decode peer BCCSP configuration\")\n\t}\n\n\treturn nil\n}\n\n// InitCrypto initializes crypto for this peer\nfunc InitCrypto(mspMgrConfigDir, localMSPID, localMSPType string) error {\n\t// Check whether msp folder exists","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/internal/peer/common/common.go#L138-L174","documentation":"InitBCCSPConfig reads the BCCSP (crypto provider) section from Viper via viper.Sub(\"peer.BCCSP\") and returns this error when that subsection is absent from the loaded configuration. It means the config file loaded into Viper has no 'peer.BCCSP' key, so no crypto provider options could be decoded. Callers are InitCrypto and tests.","triggerScenarios":"Calling InitBCCSPConfig (directly or through InitCrypto) after InitConfig loaded a config file that lacks a peer.BCCSP section — e.g. a truncated/minimal peer.yaml, or InitConfig never ran so Viper has no config at all.","commonSituations":"Using a hand-written or stripped-down peer.yaml that omits peer.BCCSP; loading an orderer.yaml-style file for a peer command; forgetting to call InitConfig (or setting FABRIC_CFG_PATH wrong) so Viper has nothing loaded; YAML indentation putting BCCSP outside the 'peer' block.","solutions":["Ensure peer.yaml contains a peer.BCCSP section (with Security Provider, Default.Provider, etc.) — copy from sampleconfig/peer.yaml.","Fix YAML indentation so BCCSP is nested under the 'peer:' key.","Confirm InitConfig ran successfully (FABRIC_CFG_PATH set, file loaded) before InitBCCSPConfig is invoked.","If configuring programmatically, set the values in the factory.FactoryOpts defaults instead of relying on Viper."],"exampleFix":"// before: peer.yaml missing section\npeer:\n  id: peer0\n\n// after\npeer:\n  id: peer0\n  BCCSP:\n    Default: SW\n    SW:\n      Hash: SHA2\n      Security: 256\n      FileKeyStore:\n        KeyStore:","handlingStrategy":"validation","validationCode":"cfgPath := os.Getenv(\"FABRIC_CFG_PATH\")\nif _, err := os.Stat(filepath.Join(cfgPath, \"peer.yaml\")); err == nil {\n\tdata, _ := ioutil.ReadFile(filepath.Join(cfgPath, \"peer.yaml\"))\n\tvar raw map[string]interface{}\n\tif yaml.Unmarshal(data, &raw) == nil {\n\t\tpeer, _ := raw[\"peer\"].(map[string]interface{})\n\t\tif _, ok := peer[\"BCCSP\"]; !ok {\n\t\t\treturn errors.New(\"peer.yaml is missing peer.BCCSP section\")\n\t\t}\n\t}\n}","typeGuard":null,"tryCatchPattern":"if err := common.InitBCCSPConfig(factory.GetDefaultOpts()); err != nil {\n\tif strings.Contains(err.Error(), \"could not get peer BCCSP configuration\") {\n\t\treturn fmt.Errorf(\"add a peer.BCCSP block to peer.yaml (see fabric sampleconfig): %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Start from the sampleconfig peer.yaml for your fabric version and edit, don't write configs from scratch.","Verify YAML indentation keeps BCCSP nested under 'peer:'.","Validate config files in CI by loading them with viper and asserting required keys exist.","Ensure InitConfig runs before any InitBCCSPConfig call."],"tags":["configuration","hyperledger-fabric","bccsp","viper"],"backgroundTag":"missing-config-section","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}