{"record":{"id":"9136fc9d8b5effc1","repo":"FuelLabs/sway","slug":"serialized-receipts-does-not-contain-th-index","errorCode":null,"errorMessage":"Serialized receipts does not contain {} th index","messagePattern":"Serialized receipts does not contain (.+?) th index","errorType":"console","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"forc-util/src/tx_utils.rs","lineNumber":25,"sourceCode":"use sway_core::{asm_generation::ProgramABI, fuel_prelude::fuel_tx};\n\n/// Added salt used to derive the contract ID.\n#[derive(Debug, Args, Default, Deserialize, Serialize)]\npub struct Salt {\n    /// Added salt used to derive the contract ID.\n    ///\n    /// By default, this is\n    /// `0x0000000000000000000000000000000000000000000000000000000000000000`.\n    #[clap(long = \"salt\")]\n    pub salt: Option<fuel_tx::Salt>,\n}\n\n/// Format `Log` and `LogData` receipts.\npub fn format_log_receipts(receipts: &[fuel_tx::Receipt], pretty_print: bool) -> Result<String> {\n    let mut receipt_to_json_array = serde_json::to_value(receipts)?;\n    for (rec_index, receipt) in receipts.iter().enumerate() {\n        let rec_value = receipt_to_json_array.get_mut(rec_index).ok_or_else(|| {\n            anyhow::anyhow!(\n                \"Serialized receipts does not contain {} th index\",\n                rec_index\n            )\n        })?;\n        match receipt {\n            fuel_tx::Receipt::LogData {\n                data: Some(data), ..\n            } => {\n                if let Some(v) = rec_value.pointer_mut(\"/LogData/data\") {\n                    *v = hex::encode(data).into();\n                }\n            }\n            fuel_tx::Receipt::ReturnData {\n                data: Some(data), ..\n            } => {\n                if let Some(v) = rec_value.pointer_mut(\"/ReturnData/data\") {\n                    *v = hex::encode(data).into();\n                }","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/FuelLabs/sway/blob/47e5e902faa42baf652dd6a0c88cd23390c1a614/forc-util/src/tx_utils.rs#L7-L43","documentation":"In format_log_receipts, receipts are serialized once with serde_json::to_value and then mutated per index to hex-encode LogData payloads. The ok_or_else guard fires if the serialized array lacks an element at rec_index — which cannot normally happen because both come from the same &[Receipt] slice. It is a defensive invariant check, not an expected runtime condition.","triggerScenarios":"Essentially unreachable via normal API use: it would require serde_json to serialize a Receipt sequence to a shorter array than its input (e.g. a Receipt variant whose Serialize impl emits a non-array element or skips values).","commonSituations":"Virtually none for end users; a fuel-tx version whose Receipt Serialize impl violates round-trip expectations could surface it during pretty-printed test logs (`forc test --pretty-print` / print_logs).","solutions":["Treat it as a bug: report the fuel-tx/froc version combination to FuelLabs","Pin fuel-tx/forc versions to a known-good pair until fixed","As a workaround, print raw receipts without pretty_print"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Defensive invariant; practically unreachable. If it fires, capture versions and report.\nmatch forc_util::format_log_receipts(&receipts, true) {\n    Ok(s) => println!(\"{s}\"),\n    Err(e) if e.to_string().contains(\"Serialized receipts\") => {\n        eprintln!(\"internal error formatting receipts (fuel-tx bug?); versions: {}\", versions());\n        // fall back to debug printing the raw receipts\n        println!(\"{receipts:#?}\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Pin fuel-tx and forc to a matched release pair in your lockfile","Report occurrences upstream with the exact fuel-tx/forc versions rather than working around them"],"tags":["forc-util","receipts","invariant","unreachable"],"backgroundTag":null,"analyzedSha":"47e5e902faa42baf652dd6a0c88cd23390c1a614","analyzedAt":"2026-08-16T07:57:45.555Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}