{"record":{"id":"823ce4d047b89f23","repo":"FuelLabs/sway","slug":"file-not-found","errorCode":null,"errorMessage":"{}: file not found","messagePattern":"(.+?): file not found","errorType":"console","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"forc-util/src/bytecode.rs","lineNumber":54,"sourceCode":"    fn next(&mut self) -> Option<InstructionWithBytes> {\n        let mut buffer = [0; fuel_asm::Instruction::SIZE];\n        // Read the next instruction into the buffer\n        match self.buf_reader.read_exact(&mut buffer) {\n            Ok(_) => fuel_asm::from_bytes(buffer)\n                .next()\n                .map(|inst| (inst, buffer.to_vec())),\n            Err(_) => None,\n        }\n    }\n}\n\n/// Parses a bytecode file into an iterator of instructions and their corresponding bytes.\npub fn parse_bytecode_to_instructions<P>(path: P) -> anyhow::Result<InstructionWithBytesIterator>\nwhere\n    P: AsRef<Path> + Clone,\n{\n    let f = File::open(path.clone())\n        .map_err(|_| anyhow!(\"{}: file not found\", path.as_ref().to_string_lossy()))?;\n    let buf_reader = BufReader::new(f);\n\n    Ok(InstructionWithBytesIterator::new(buf_reader))\n}\n\n/// Gets the bytecode ID from a bytecode file. The bytecode ID is the hash of the bytecode after removing the\n/// condigurables section, if any.\npub fn get_bytecode_id<P>(path: P) -> anyhow::Result<String>\nwhere\n    P: AsRef<Path> + Clone,\n{\n    let mut instructions = parse_bytecode_to_instructions(path.clone())?;\n\n    // Collect the first six instructions into a temporary vector\n    let mut first_six_instructions = Vec::with_capacity(CONFIGURABLES_OFFSET_PREAMBLE);\n    for _ in 0..CONFIGURABLES_OFFSET_PREAMBLE {\n        if let Some(instruction) = instructions.next() {\n            first_six_instructions.push(instruction);","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/FuelLabs/sway/blob/47e5e902faa42baf652dd6a0c88cd23390c1a614/forc-util/src/bytecode.rs#L36-L72","documentation":"parse_bytecode_to_instructions in forc-util fails to File::open the given bytecode file and maps every open error to \"<path>: file not found\". The underlying io::Error is discarded (map_err(|_| ...)), so permission denied and true missing-file are indistinguishable. This parser feeds get_bytecode_id, used by forc contract-id / forc predicate-root bytecode hashing.","triggerScenarios":"Calling get_bytecode_id / parse_bytecode_to_instructions with a wrong, moved, or unreadable path — e.g. `forc contract-id --bytecode-file out/debug/old-name.bin` after the project was renamed, or running from a directory where the relative output path does not resolve.","commonSituations":"Stale hardcoded paths in scripts after `forc build` output names change (binary named after the package), wrong cwd when invoking forc commands with relative paths, or file permissions blocking read access.","solutions":["Rebuild the project (`forc build`) and point at the freshly generated .bin under out/debug|release","Verify the path from the directory you actually invoke forc from, or use an absolute path","Check file permissions if the file visibly exists (the message cannot distinguish a permission failure)"],"exampleFix":"# before\nforc contract-id --bytecode-file out/debug/counter.bin   # renamed package\n\n# after\nforc build && forc contract-id --bytecode-file out/debug/my_renamed_pkg.bin","handlingStrategy":"validation","validationCode":"let path = std::path::Path::new(bytecode_path);\nif !path.is_file() {\n    anyhow::bail!(\"bytecode file '{}' not found or unreadable\", path.display());\n}\nlet id = forc_util::bytecode::get_bytecode_id(path)?;","typeGuard":"fn readable_bin(p: &std::path::Path) -> bool {\n    std::fs::metadata(p).map(|m| m.is_file()).unwrap_or(false)\n}","tryCatchPattern":"match forc_util::bytecode::get_bytecode_id(&path) {\n    Ok(id) => Ok(id),\n    Err(e) if e.to_string().ends_with(\"file not found\") => {\n        Err(anyhow::anyhow!(\"build the project first: forc build (looked in {})\", path.display()))\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Derive the .bin path from the package name (out/debug/<pkg>.bin) instead of hardcoding it in scripts","Run `forc build` as a prerequisite step before any contract-id/predicate-root command"],"tags":["forc-util","bytecode","file-not-found","contract-id"],"backgroundTag":null,"analyzedSha":"47e5e902faa42baf652dd6a0c88cd23390c1a614","analyzedAt":"2026-08-16T07:57:45.555Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}