{"record":{"id":"1c668332497b1815","repo":"hyperledger/fabric","slug":"error-in-instantiating-ledger-provider-v","errorCode":null,"errorMessage":"Error in instantiating ledger provider: %+v","messagePattern":"Error in instantiating ledger provider: %\\+v","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"core/ledger/ledgermgmt/ledger_mgmt.go","lineNumber":85,"sourceCode":"\tfinalStateListeners := addListenerForCCEventsHandler(\n\t\tinitializer.DeployedChaincodeInfoProvider,\n\t\tinitializer.StateListeners,\n\t)\n\tprovider, err := kvledger.NewProvider(\n\t\t&ledger.Initializer{\n\t\t\tStateListeners:                  finalStateListeners,\n\t\t\tDeployedChaincodeInfoProvider:   initializer.DeployedChaincodeInfoProvider,\n\t\t\tMembershipInfoProvider:          initializer.MembershipInfoProvider,\n\t\t\tChaincodeLifecycleEventProvider: initializer.ChaincodeLifecycleEventProvider,\n\t\t\tMetricsProvider:                 initializer.MetricsProvider,\n\t\t\tHealthCheckRegistry:             initializer.HealthCheckRegistry,\n\t\t\tConfig:                          initializer.Config,\n\t\t\tCustomTxProcessors:              initializer.CustomTxProcessors,\n\t\t\tHashProvider:                    initializer.HashProvider,\n\t\t},\n\t)\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"Error in instantiating ledger provider: %+v\", err))\n\t}\n\tledgerMgr := &LedgerMgr{\n\t\tjoinBySnapshotStatus: &pb.JoinBySnapshotStatus{},\n\t\topenedLedgers:        make(map[string]ledger.PeerLedger),\n\t\tledgerProvider:       provider,\n\t\tebMetadataProvider:   initializer.EbMetadataProvider,\n\t}\n\t// TODO remove the following package level init\n\tcceventmgmt.Initialize(&chaincodeInfoProviderImpl{\n\t\tledgerMgr,\n\t\tinitializer.DeployedChaincodeInfoProvider,\n\t})\n\tlogger.Info(\"Initialized LedgerMgr\")\n\treturn ledgerMgr\n}\n\n// CreateLedger creates a new ledger with the given genesis block.\n// This function guarantees that the creation of ledger and committing the genesis block would an atomic action.","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/ledger/ledgermgmt/ledger_mgmt.go#L67-L103","documentation":"NewLedgerMgr calls kvledger.NewProvider to instantiate the underlying ledger provider; if that fails the manager cannot function, so it panics with this message embedding the original error (%+v). Root causes are whatever NewProvider returns: bad ledger config, unwritable/inaccessible data directories, corrupted LevelDB stores, CouchDB connection failures, etc.","triggerScenarios":"kvledger.NewProvider returning an error due to invalid ledger.Config (bad RootFSPath/StateDBConfig), inability to open the ledgerProvider LevelDB, CouchDB unreachable when stateDatabase is CouchDB, or corrupted ledger databases — causing NewLedgerMgr to panic.","commonSituations":"Misconfigured peer.fileSystemPath (missing or permission-denied directory); CouchDB credentials or address wrong in core.yaml; ledger data corrupted after disk-full or unclean shutdown; running the embedded ledger code without a valid config in tests.","solutions":["Read the wrapped error in the panic message (%+v) to find the root cause (config path, CouchDB connection, or corrupted DB).","Fix ledger configuration: verify peer.fileSystemPath exists and is writable; verify state database settings in core.yaml (CouchDB address/credentials) and that CouchDB is reachable.","If ledger data is corrupted, restore from backup or recreate the data directory; for known format issues, run the appropriate kvledger repair/upgrade tools.","Ensure the process has filesystem permissions and sufficient disk space for the ledger directories before startup."],"exampleFix":"// before (swallows config validation, panics later)\nledgermgmt.NewLedgerMgr(&Initializer{Config: cfg})\n\n// after (validate first)\nif _, err := os.Stat(cfg.RootFSPath); err != nil {\n    os.MkdirAll(cfg.RootFSPath, 0o755) // ensure ledger dir exists before NewProvider\n}\nledgermgmt.NewLedgerMgr(&Initializer{Config: cfg})","handlingStrategy":"validation","validationCode":"// validate config before NewLedgerMgr to avoid the panic\nif fi, err := os.Stat(config.RootFSPath); err != nil || !fi.IsDir() {\n    return fmt.Errorf(\"ledger RootFSPath %q missing or not a directory\", config.RootFSPath)\n}\nif config.StateDBConfig.StateDatabase == ledger.CouchDB {\n    if err := pingCouchDB(config.StateDBConfig.CouchDB); err != nil {\n        return fmt.Errorf(\"CouchDB unreachable: %w\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":"// NewLedgerMgr panics rather than returning error; recover at startup boundary\nfunc safeNewLedgerMgr(init *ledgermgmt.Initializer) (mgr *ledgermgmt.LedgerMgr, err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"ledger provider init failed: %v\", r)\n        }\n    }()\n    return ledgermgmt.NewLedgerMgr(init), nil\n}","preventionTips":["Verify peer.fileSystemPath exists, is writable, and has free disk space before startup","Test CouchDB connectivity and credentials when StateDatabase is CouchDB","Guard against corrupted ledger DBs with backups and clean-shutdown procedures","Wrap NewLedgerMgr in a recover at the bootstrap boundary since it panics on failure"],"tags":["go","hyperledger-fabric","panic","initialization","configuration"],"backgroundTag":"provider-init-panic","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"}