{"record":{"id":"80d7bb1b67a900dc","repo":"hyperledger/fabric","slug":"could-not-find-config-file-please-make-sure-that","errorCode":null,"errorMessage":"Could not find config file. Please make sure that FABRIC_CFG_PATH is set to a path which contains peer.yaml","messagePattern":"Could not find config file\\. Please make sure that FABRIC_CFG_PATH is set to a path which contains peer\\.yaml","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/peer/common/common.go","lineNumber":139,"sourceCode":"\tGetOrdererEndpointOfChainFnc = GetOrdererEndpointOfChain\n\tGetDeliverClientFnc = GetDeliverClient\n\tGetPeerDeliverClientFnc = GetPeerDeliverClient\n\tGetClientCertificateFnc = GetClientCertificate\n}\n\n// InitConfig initializes viper config\nfunc InitConfig(cmdRoot string) error {\n\terr := config.InitViper(nil, cmdRoot)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\terr = viper.ReadInConfig() // Find and read the config file\n\tif err != nil {            // Handle errors reading the config file\n\t\t// The version of Viper we use claims the config type isn't supported when in fact the file hasn't been found\n\t\t// Display a more helpful message to avoid confusing the user.\n\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}","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/internal/peer/common/common.go#L121-L157","documentation":"This error is thrown by InitConfig in internal/peer/common/common.go when Viper fails to read the command's YAML config file (e.g. peer.yaml). The Hyperledger Fabric viper version reports 'Unsupported Config Type' when the file simply isn't found, so the code translates that into a clearer message telling the user FABRIC_CFG_PATH must point to a directory containing the expected <cmdRoot>.yaml. It is an environment/configuration setup problem, not a code bug.","triggerScenarios":"Calling InitConfig (via peer InitCmd, or test helpers initPeerTestEnv/initOrdererTestEnv) when viper.ReadInConfig() fails with an error containing 'Unsupported Config Type' — i.e. FABRIC_CFG_PATH is unset, empty, or points to a directory that does not contain <cmdRoot>.yaml (peer.yaml for the peer binary).","commonSituations":"Running the peer node without exporting FABRIC_CFG_PATH; pointing FABRIC_CFG_PATH at the wrong directory (e.g. the crypto-config dir instead of the sampleconfig dir); renaming or deleting peer.yaml; running binaries outside the fabric-samples environment; Docker containers started without the config volume mounted.","solutions":["Set FABRIC_CFG_PATH to the directory containing peer.yaml, e.g. export FABRIC_CFG_PATH=$PWD/ or /etc/hyperledger/fabric (sampleconfig is in the fabric source tree).","Verify the file exists: ls $FABRIC_CFG_PATH/peer.yaml; if missing, copy sampleconfig/peer.yaml from the fabric repo.","In Docker, mount the config: -v <host-config>:/etc/hyperledger/fabric and confirm the peer container's FABRIC_CFG_PATH env var matches.","If the file exists but is malformed/unreadable, fix permissions or YAML syntax, then retry."],"exampleFix":"// before (config not found)\npeer node start\n\n// after (set config path first)\nexport FABRIC_CFG_PATH=/etc/hyperledger/fabric\npeer node start","handlingStrategy":"validation","validationCode":"cfgPath := os.Getenv(\"FABRIC_CFG_PATH\")\nif cfgPath == \"\" {\n\treturn fmt.Errorf(\"FABRIC_CFG_PATH is not set\")\n}\nif _, err := os.Stat(filepath.Join(cfgPath, \"peer.yaml\")); err != nil {\n\treturn fmt.Errorf(\"%s does not contain peer.yaml\", cfgPath)\n}","typeGuard":null,"tryCatchPattern":"if err := common.InitConfig(cmdRoot); err != nil {\n\tif strings.Contains(err.Error(), \"Could not find config file\") {\n\t\tlog.Fatalf(\"config setup: set FABRIC_CFG_PATH to a dir containing %s.yaml: %v\", cmdRoot, err)\n\t}\n\treturn err\n}","preventionTips":["Always export FABRIC_CFG_PATH in shell profiles or container env before running peer binaries.","Add a startup check that peer.yaml exists under FABRIC_CFG_PATH.","Mount the config directory explicitly in Docker/K8s deployments and verify with an init container.","Keep peer.yaml sourced from the fabric sampleconfig for your fabric version to avoid schema drift."],"tags":["configuration","hyperledger-fabric","env-var","viper"],"backgroundTag":"missing-env-var","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"}