{"record":{"id":"80c2c3d3996f4983","repo":"FuelLabs/fuels-rs","slug":"failed-to-load-the-contract","errorCode":null,"errorMessage":"Failed to load the contract","messagePattern":"Failed to load the contract","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/fuels-macros/src/setup_program_test/code_gen.rs","lineNumber":155,"sourceCode":"                    // These lines must be inside the `quote!` macro, otherwise the salt remains\n                    // identical between macro compilation, causing contract id collision.\n                    ::fuels::test_helpers::generate_random_salt()\n                }\n            } else {\n                quote! { [0; 32] }\n            };\n\n            quote! {\n                let salt: [u8; 32] = #salt;\n\n                let #contract_instance_name = {\n                    let load_config = ::fuels::programs::contract::LoadConfiguration::default().with_salt(salt);\n\n                    let loaded_contract = ::fuels::programs::contract::Contract::load_from(\n                        #bin_path,\n                        load_config\n                    )\n                    .expect(\"Failed to load the contract\");\n\n                    let response = loaded_contract.deploy_if_not_exists(\n                        &#wallet_name,\n                        ::fuels::types::transaction::TxPolicies::default()\n                    )\n                    .await\n                    .expect(\"Failed to deploy the contract\");\n\n                    #contract_struct_name::new(response.contract_id, #wallet_name.clone())\n                };\n            }\n        })\n        .reduce(|mut all_code, code| {\n            all_code.extend(code);\n            all_code\n        })\n        .unwrap_or_default()\n}","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/FuelLabs/fuels-rs/blob/d9a250a51818dda64bfeb5ef7cc19cf27bdcd623/packages/fuels-macros/src/setup_program_test/code_gen.rs#L137-L173","documentation":"For each contract declared in setup_program_test!, the generated code calls Contract::load_from(bin_path, load_config) synchronously and expects success. The panic means the compiled contract binary could not be read or parsed: the file is missing, empty, or not a valid fuel binary.","triggerScenarios":"The bin path given in the macro (e.g. \"tests/contracts/my_contract/out/release/my_contract.bin\") does not exist because forc build was never run, or the .bin file is corrupt/empty.","commonSituations":"Running cargo test before building contracts; typo in the contract path; CI pipelines that skip the forc build step.","solutions":["Build the contract: forc build --release so the binary exists at the path passed to the macro","Verify the path string and that the .bin file is non-empty","Wire CI (or a justfile/build.rs) to run forc build before cargo test"],"exampleFix":"# before\ncargo test # panics: \"Failed to load the contract\" — binary missing\n\n# after\nforc build --release\ncargo test","handlingStrategy":"validation","validationCode":"// Fail fast when the contract binary is missing before deployment-heavy tests\nlet bin = \"tests/contracts/my_contract/out/release/my_contract.bin\";\nassert!(\n    std::path::Path::new(bin).exists(),\n    \"contract binary missing — run `forc build --release` first\"\n);","typeGuard":null,"tryCatchPattern":"// In manual setup code, propagate instead of expecting:\nlet loaded = Contract::load_from(bin, LoadConfiguration::default())\n    .with_context(|| format!(\"failed to load contract binary at {bin}\"))?;","preventionTips":["Run forc build --release before cargo test (wire it into CI or a justfile)","Assert binary existence in a lightweight pre-test","Keep contract paths in one place to avoid typos"],"tags":["test-helpers","proc-macro","contract","build","deployment"],"backgroundTag":null,"analyzedSha":"d9a250a51818dda64bfeb5ef7cc19cf27bdcd623","analyzedAt":"2026-08-16T09:49:30.618Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}