{"record":{"id":"a0e3172c83e00867","repo":"hyperledger/fabric","slug":"error-truncating-the-block-file-s","errorCode":null,"errorMessage":"error truncating the block file [%s]","messagePattern":"error truncating the block file \\[(.+?)\\]","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/ledger/blkstorage/rollback.go","lineNumber":204,"sourceCode":"\tlogger.Infof(\"Removing all block files with suffixNum in the range [%d] to [%d]\",\n\t\ttargetFileNum+1, lastFileNum)\n\n\tfor n := lastFileNum; n >= targetFileNum+1; n-- {\n\t\tfilepath := deriveBlockfilePath(r.ledgerDir, n)\n\t\tif err := os.Remove(filepath); err != nil {\n\t\t\treturn errors.Wrapf(err, \"error removing the block file [%s]\", filepath)\n\t\t}\n\t}\n\n\tlogger.Infof(\"Truncating block file [%d] to the end boundary of block number [%d]\", targetFileNum, r.targetBlockNum)\n\tendOffset, err := calculateEndOffSet(r.ledgerDir, targetFileNum, r.targetBlockNum)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tfilePath := deriveBlockfilePath(r.ledgerDir, targetFileNum)\n\tif err := os.Truncate(filePath, endOffset); err != nil {\n\t\treturn errors.Wrapf(err, \"error truncating the block file [%s]\", filePath)\n\t}\n\n\treturn nil\n}\n\nfunc calculateEndOffSet(ledgerDir string, targetBlkFileNum int, blockNum uint64) (int64, error) {\n\tstream, err := newBlockfileStream(ledgerDir, targetBlkFileNum, 0)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\tdefer stream.close()\n\tfor {\n\t\tblockBytes, err := stream.nextBlockBytes()\n\t\tif err != nil {\n\t\t\treturn 0, err\n\t\t}\n\t\tblockInfo, err := extractSerializedBlockInfo(blockBytes)\n\t\tif err != nil {","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/common/ledger/blkstorage/rollback.go#L186-L222","documentation":"Returned by rollbackBlockFiles when truncating the target block file to the rollback boundary fails at the OS level (I/O error, permissions). The higher-numbered files were already removed; this is the final in-place truncation step failing.","triggerScenarios":"Thrown at common/ledger/blkstorage/rollback.go:204 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the wrapped error for the OS cause (permissions, disk, read-only FS)","Verify filesystem health and rerun the rollback with the peer down"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}