{"record":{"id":"12b0aa5da7ddcc72","repo":"FuelLabs/fuels-rs","slug":"failed-to-read-binary-binary-filepath-e","errorCode":null,"errorMessage":"failed to read binary: {binary_filepath:?}: {e}","messagePattern":"failed to read binary: (.+?): (.+?)","errorType":"exception","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"packages/fuels-programs/src/contract/regular.rs","lineNumber":115,"sourceCode":"\n    pub fn state_root(&self) -> Bytes32 {\n        self.compute_roots().2\n    }\n\n    fn compute_roots(&self) -> (ContractId, Bytes32, Bytes32) {\n        compute_contract_id_and_state_root(&self.code(), &self.salt, &self.storage_slots)\n    }\n\n    /// Loads a contract from a binary file. Salt and storage slots are loaded as well, depending on the configuration provided.\n    pub fn load_from(\n        binary_filepath: impl AsRef<Path>,\n        config: LoadConfiguration,\n    ) -> Result<Contract<Regular>> {\n        let binary_filepath = binary_filepath.as_ref();\n        validate_path_and_extension(binary_filepath, \"bin\")?;\n\n        let binary = std::fs::read(binary_filepath).map_err(|e| {\n            std::io::Error::new(\n                e.kind(),\n                format!(\"failed to read binary: {binary_filepath:?}: {e}\"),\n            )\n        })?;\n\n        let storage_slots = super::determine_storage_slots(config.storage, binary_filepath)?;\n\n        Ok(Contract {\n            code: Regular::new(binary, config.configurables),\n            salt: config.salt,\n            storage_slots,\n        })\n    }\n\n    /// Creates a regular contract with the given code, salt, and storage slots.\n    pub fn regular(\n        code: Vec<u8>,\n        salt: Salt,","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/FuelLabs/fuels-rs/blob/d9a250a51818dda64bfeb5ef7cc19cf27bdcd623/packages/fuels-programs/src/contract/regular.rs#L97-L133","documentation":"Runtime IO error from Contract::load_from in fuels-programs: the contract binary file passed its existence and .bin-extension validation (validate_path_and_extension) but std::fs::read then failed. The original io::ErrorKind is preserved and the message carries the exact path and OS-level cause, so failures here are I/O-level (permissions, race with a deleted file, symlink issues), not 'file not found'.","triggerScenarios":"Calling Contract::load_from(\"path/contract.bin\", config) where the file exists with the right extension but the process cannot read it: EACCES on restrictive permissions, the file being removed between the existence check and the read, a broken symlink whose target validate_path_and_extension happened to accept, or reading a directory-like special path.","commonSituations":"CI running as a low-privilege user over files produced by another user's forc build; out/ artifacts cleaned mid-run by a parallel cargo/forc task; files synced from another OS with lost permissions; paths referencing network mounts that became unavailable.","solutions":["Check the embedded {e} cause: 'Permission denied (os error 13)' → chmod 644 the file or adjust the running user; 'No such file or directory' → the file vanished between check and read, rebuild artifacts.","Verify the path points to the actual forc output binary (typically <project>/out/debug/<name>.bin) and that forc build completed before load_from runs.","If artifacts are produced in parallel, ensure the build step finishes (make/turbo dependency) before loading.","Retry once after re-running forc build if the artifact was transiently missing."],"exampleFix":"// before\nlet contract = Contract::load_from(\"../out/debug/counter.bin\", LoadConfiguration::default())?;\n// after: validate readability up front with a clear message\nlet path = std::path::Path::new(\"../out/debug/counter.bin\");\nstd::fs::File::open(path).with_context(|| format!(\"cannot open {} — run `forc build` and check permissions\", path.display()))?;\nlet contract = Contract::load_from(path, LoadConfiguration::default())?;","handlingStrategy":"try-catch","validationCode":"let path = std::path::Path::new(binary_path);\nif !path.is_file() {\n    anyhow::bail!(\"{path:?} is not a file — run `forc build` first\");\n}\nstd::fs::metadata(path).with_context(|| format!(\"unreadable: {}\", path.display()))?;\n// extension check mirroring the library's own guard\nassert_eq!(path.extension().and_then(|e| e.to_str()), Some(\"bin\"), \"expected a .bin file\");","typeGuard":null,"tryCatchPattern":"match Contract::load_from(&path, cfg) {\n    Err(e) if e.to_string().contains(\"failed to read binary\") => {\n        // IO-level failure after existence+extension checks: inspect permissions,\n        // rebuild artifacts with forc, then retry once\n        rebuild_with_forc()?;\n        Contract::load_from(&path, cfg)\n    }\n    other => other,\n}","preventionTips":["Run forc build (and wait for completion) before loading binaries in tests/CI.","Ensure the process user has read permission on out/debug/*.bin artifacts.","Load from canonical, stable paths (e.g. derived from CARGO_MANIFEST_DIR) rather than relative paths sensitive to cwd."],"tags":["rust","runtime","io","contract","fuels-programs"],"backgroundTag":null,"analyzedSha":"d9a250a51818dda64bfeb5ef7cc19cf27bdcd623","analyzedAt":"2026-08-16T09:49:30.618Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}