{"record":{"id":"3baff2ab8ce10aba","repo":"diem/diem","slug":"unable-to-get-txn-iter","errorCode":null,"errorMessage":"Unable to get txn iter","messagePattern":"Unable to get txn iter","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"storage/inspector/src/main.rs","lineNumber":113,"sourceCode":"                info!(\n                    \"Account {} exists, but have no AccountResource: {}.\",\n                    addr, e\n                );\n            }\n        }\n    } else {\n        info!(\"Account {} doesn't exists\", addr);\n    }\n}\n\nfn list_txns(db: &DiemDB) {\n    let version = db\n        .get_latest_version()\n        .expect(\"Unable to get latest version\");\n    let backup = db.get_backup_handler();\n    let iter = backup\n        .get_transaction_iter(0, version as usize)\n        .expect(\"Unable to get txn iter\");\n    for (v, tx) in iter.enumerate() {\n        println!(\n            \"TXN {}: {}\",\n            v,\n            tx.expect(\"Unable to read TX\")\n                .0\n                .format_for_client(|bytes| name_for_script(bytes).unwrap())\n        );\n    }\n}\n\nfn list_accounts(db: &DiemDB) {\n    let version = db\n        .get_latest_version()\n        .expect(\"Unable to get latest version\");\n    let backup = db.get_backup_handler();\n    let iter = backup\n        .get_account_iter(version)","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/diem/diem/blob/fc4714a8ea273b6efe8b13dbce72ea60aad9a16c/storage/inspector/src/main.rs#L95-L131","documentation":"Panic from `.expect()` on `BackupHandler::get_transaction_iter(0, version)`, which opens a RocksDB iterator over raw transactions from version 0 to the latest version. The underlying Result carries the storage error (I/O failure, invalid version range, or DB handle problem) and turning it into an expect aborts the process.","triggerScenarios":"`list_txns` where version is huge/invalid relative to actual DB contents, the transaction column family is missing or corrupted, or RocksDB fails to create the iterator (I/O error, corrupt SST file).","commonSituations":"Running on a DB restored partially from backup (transaction history truncated below `version`), corrupted RocksDB data files after a crash, or requesting a range that no longer exists after pruning.","solutions":["Retry with a smaller end version within the DB's actual transaction range","Check RocksDB logs in the DB directory for corruption and run a repair or restore from backup","Ensure the DB was not pruned below version 0 unexpectedly; use the pruner-aware range","Rebuild the inspector against the same DB schema version"],"exampleFix":"// before\nlet iter = backup\n    .get_transaction_iter(0, version as usize)\n    .expect(\"Unable to get txn iter\");\n// after\nlet iter = match backup.get_transaction_iter(0, version as usize) {\n    Ok(it) => it,\n    Err(e) => { eprintln!(\"Cannot open txn iter: {:?}\", e); return; }\n};","handlingStrategy":"try-catch","validationCode":"// Bound the range to what the DB actually holds:\n// if version == 0 or history was pruned, do not request from 0..version\n// check RocksDB logs for corruption before iterating","typeGuard":null,"tryCatchPattern":"let iter = match backup.get_transaction_iter(0, version as usize) {\n    Ok(it) => it,\n    Err(e) => { eprintln!(\"Unable to get txn iter: {:?}\", e); return; }\n};","preventionTips":["Avoid opening iterators over pruned or truncated ranges","Keep the DB out of write while iterating","Monitor RocksDB for corruption after unclean shutdowns and repair first"],"tags":["rust","storage","rocksdb","backup","panic"],"backgroundTag":"database-read-failure","analyzedSha":"fc4714a8ea273b6efe8b13dbce72ea60aad9a16c","analyzedAt":"2026-09-04T21:07:05.890Z","contentChangedAt":"2026-09-04T21:07:05.890Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}