{"record":{"id":"7b05d0a48e7ec7fd","repo":"hyperledger/fabric","slug":"could-not-build-blockfilesinfo-info-from-block-fil","errorCode":null,"errorMessage":"Could not build blockfilesInfo info from block files: %s","messagePattern":"Could not build blockfilesInfo info from block files: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"common/ledger/blkstorage/blockfile_mgr.go","lineNumber":111,"sourceCode":"\t  *)  Updates blockchain info used by the APIs\n*/\nfunc newBlockfileMgr(id string, conf *Conf, indexConfig *IndexConfig, indexStore *leveldbhelper.DBHandle) (*blockfileMgr, error) {\n\tlogger.Debugf(\"newBlockfileMgr() initializing file-based block storage for ledger: %s \", id)\n\trootDir := conf.getLedgerBlockDir(id)\n\t_, err := fileutil.CreateDirIfMissing(rootDir)\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"Error creating block storage root dir [%s]: %s\", rootDir, err))\n\t}\n\tmgr := &blockfileMgr{rootDir: rootDir, conf: conf, db: indexStore, cache: newCache(defaultBlockCacheSizeBytes)}\n\n\tblockfilesInfo, err := mgr.loadBlkfilesInfo()\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"Could not get block file info for current block file from db: %s\", err))\n\t}\n\tif blockfilesInfo == nil {\n\t\tlogger.Info(`Getting block information from block storage`)\n\t\tif blockfilesInfo, err = constructBlockfilesInfo(rootDir); err != nil {\n\t\t\tpanic(fmt.Sprintf(\"Could not build blockfilesInfo info from block files: %s\", err))\n\t\t}\n\t\tlogger.Debugf(\"Info constructed by scanning the blocks dir = %s\", spew.Sdump(blockfilesInfo))\n\t} else {\n\t\tlogger.Debug(`Syncing block information from block storage (if needed)`)\n\t\tsyncBlockfilesInfoFromFS(rootDir, blockfilesInfo)\n\t}\n\terr = mgr.saveBlkfilesInfo(blockfilesInfo, true)\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"Could not save next block file info to db: %s\", err))\n\t}\n\n\tcurrentFileWriter, err := newBlockfileWriter(deriveBlockfilePath(rootDir, blockfilesInfo.latestFileNumber))\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"Could not open writer to current file: %s\", err))\n\t}\n\terr = currentFileWriter.truncateFile(blockfilesInfo.latestFileSize)\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"Could not truncate current file to known size in db: %s\", err))","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/common/ledger/blkstorage/blockfile_mgr.go#L93-L129","documentation":"Panic when constructBlockfilesInfo cannot rebuild blockfilesInfo by scanning the block files directory (used only when the DB checkpoint record is absent, e.g. first start after index reset). It means the FS scan failed (stat/read errors on files) so block storage cannot initialize.","triggerScenarios":"constructBlockfilesInfo returns an error — typically getFileInfoOrPanic Lstat failure on a block file, or inability to read the last file — when blockfilesInfo == nil during newBlockfileMgr.","commonSituations":"Block files missing or unreadable while the index DB was reset/empty (mismatched index vs chains dirs); partial backup restore; permission problems on chains/<ledgerID>.","solutions":["Restore the complete chains/<ledgerID> block files (index and chains dirs must come from the same backup)","Fix permissions/ownership of the block files so the scanner can stat them","If the ledger is disposable, delete both the ledger dir and its index entries to start fresh"],"exampleFix":"// before: restoring only the index DB without chains files\n// after: restore index and chains dirs together from the same snapshot\n// rsync -a snapshot/ledgersData/ ledgersData/","handlingStrategy":"validation","validationCode":"// ensure FS scan will succeed: all existing block files are statable\nentries, err := os.ReadDir(filepath.Join(rootDir))\nif err != nil { return err }\nfor _, e := range entries {\n    if _, err := os.Lstat(filepath.Join(rootDir, e.Name())); err != nil {\n        return fmt.Errorf(\"unreadable entry %s: %w\", e.Name(), err)\n    }\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        err = fmt.Errorf(\"cannot reconstruct blockfilesInfo: %v\", r)\n    }\n}()","preventionTips":["Never restore the index DB without the matching chains files (or vice versa)","Fix ownership/permissions on chains/<ledgerID> before peer start","Complete backup restores before starting the peer"],"tags":["filesystem","ledger-storage","panic"],"backgroundTag":"file-not-found","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"}