{"record":{"id":"34be2441667a627b","repo":"hyperledger/fabric","slug":"snapshot-dir-s-is-empty","errorCode":null,"errorMessage":"snapshot dir %s is empty","messagePattern":"snapshot dir (.+?) is empty","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/ledger/ledgermgmt/ledger_mgmt.go","lineNumber":141,"sourceCode":"\treturn &closableLedger{\n\t\tledgerMgr:  m,\n\t\tid:         id,\n\t\tPeerLedger: l,\n\t}, nil\n}\n\n// CreateLedgerFromSnapshot creates a new ledger with the given snapshot and executes the callback function\n// after the ledger is created. This function launches to goroutine to create the ledger and call the callback func.\n// All ledger dbs would be created in an atomic action. The channel id retrieved from the snapshot metadata\n// is treated as a ledger id. It returns an error if another ledger is being created from a snapshot.\nfunc (m *LedgerMgr) CreateLedgerFromSnapshot(snapshotDir string, channelCallback func(ledger.PeerLedger, string)) error {\n\t// verify snapshotDir exists and is not empty\n\tempty, err := fileutil.DirEmpty(snapshotDir)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif empty {\n\t\treturn errors.Errorf(\"snapshot dir %s is empty\", snapshotDir)\n\t}\n\n\tif err := m.setJoinBySnapshotStatus(snapshotDir); err != nil {\n\t\treturn err\n\t}\n\n\tgo func() {\n\t\tdefer m.resetJoinBySnapshotStatus()\n\n\t\tledger, cid, err := m.createFromSnapshot(snapshotDir)\n\t\tif err != nil {\n\t\t\tlogger.Errorw(\"Error creating ledger from snapshot\", \"snapshotDir\", snapshotDir, \"error\", err)\n\t\t\treturn\n\t\t}\n\n\t\tchannelCallback(ledger, cid)\n\t}()\n","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/ledger/ledgermgmt/ledger_mgmt.go#L123-L159","documentation":"CreateLedgerFromSnapshot validates that the supplied snapshotDir exists and is non-empty before starting the join-by-snapshot bootstrap. fileutil.DirEmpty reports the directory has no content, meaning the snapshot metadata/files were never generated, were deleted, or the wrong path was given. The operation is aborted before any state is changed.","triggerScenarios":"Calling LedgerMgr.CreateLedgerFromSnapshot(snapshotDir) where snapshotDir exists but contains no files (e.g. snapshot generation never completed, files moved, or the root of the snapshots directory was passed instead of a specific snapshot's directory).","commonSituations":"Configuring peer.core.yaml's ledger.snapshots.rootDir and pointing joinBySnapshot at the root instead of an actual snapshot directory; a snapshot whose files were lost during transfer to the joining peer; a crashed/partial snapshot generation.","solutions":["Point the operation at a concrete snapshot directory (rootDir/generatedSnapshots/<snapshotName>) that contains snapshot files, not the snapshots root.","Verify the snapshot files were copied intact to this peer; re-transfer if missing.","If no valid snapshot exists, generate a new one on a source peer (GenerateSnapshot) and retry."],"exampleFix":"// before\nmgr.CreateLedgerFromSnapshot(\"/var/hyperledger/production/snapshots\")\n// after\nmgr.CreateLedgerFromSnapshot(\"/var/hyperledger/production/snapshots/completedSnapshots/snapshot-123\")","handlingStrategy":"validation","validationCode":"entries, err := os.ReadDir(snapshotDir)\nif err != nil || len(entries) == 0 {\n    return fmt.Errorf(\"snapshot dir %s missing or empty\", snapshotDir)\n}","typeGuard":null,"tryCatchPattern":"if err := mgr.CreateLedgerFromSnapshot(dir); err != nil {\n    if strings.Contains(err.Error(), \"is empty\") {\n        // fall back to genesis-block join or re-copy snapshot\n    }\n    return err\n}","preventionTips":["Pass the exact snapshot directory (rootDir/generatedSnapshots/<name>), never the snapshots root.","Verify file counts/checksums after transferring snapshots between peers.","Confirm snapshot generation completed successfully before initiating the join."],"tags":["ledger","snapshot","filesystem","fabric"],"backgroundTag":"empty-snapshot-directory","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"}