{"record":{"id":"ce51f6cfdb207726","repo":"linera-io/linera-protocol","slug":"failed-to-load-contract-bytecode-from-contract","errorCode":null,"errorMessage":"failed to load contract bytecode from {contract:?}: {e}","messagePattern":"failed to load contract bytecode from (.+?): (.+?)","errorType":"exception","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"linera-client/src/client_context.rs","lineNumber":854,"sourceCode":"            chain_info,\n        })\n    }\n}\n\n#[cfg(feature = \"fs\")]\nimpl<Env: Environment> ClientContext<Env> {\n    /// Publishes a module from its contract and service bytecode files.\n    pub async fn publish_module(\n        &mut self,\n        chain_client: &ChainClient<Env>,\n        contract: PathBuf,\n        service: PathBuf,\n        vm_runtime: VmRuntime,\n        formats: Option<PathBuf>,\n    ) -> Result<ModuleId, Error> {\n        info!(\"Loading bytecode files\");\n        let contract_bytecode = Bytecode::load_from_file(&contract).await.map_err(|e| {\n            std::io::Error::new(\n                e.kind(),\n                format!(\"failed to load contract bytecode from {contract:?}: {e}\"),\n            )\n        })?;\n        let service_bytecode = Bytecode::load_from_file(&service).await.map_err(|e| {\n            std::io::Error::new(\n                e.kind(),\n                format!(\"failed to load service bytecode from {service:?}: {e}\"),\n            )\n        })?;\n\n        let formats_bytes = match formats {\n            Some(path) => Some(bcs::to_bytes(&load_formats_from_snap(&path)?)?),\n            None => None,\n        };\n\n        info!(\"Publishing module\");\n        let (blobs, module_id) = create_bytecode_blobs(","sourceCodeStart":836,"sourceCodeEnd":872,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-client/src/client_context.rs#L836-L872","documentation":"ClientContext::publish_module loads the contract half of an application from the --contract path using Bytecode::load_from_file, re-wrapping any I/O failure with the specific contract path. This is the contract-side twin of the service error at line 860; which one fires tells you which path argument was bad. The error is a plain I/O condition (kind preserved), not a Wasm-validation failure.","triggerScenarios":"Calling publish_module (the `linera publish-module --contract <path> --service <path>` flow) where the --contract path is missing, unreadable, a directory, or a dangling symlink. It fires before the service path is read or any chain communication starts.","commonSituations":"Publishing before `cargo build --target wasm32-unknown-unknown --release` (or `linera build`) produced the contract .wasm; pointing --contract at the native target dir; a typo in the filename; running from the wrong working directory with a relative path; CI artifacts not copied into the job's container.","solutions":["Check the exact --contract path exists and is a file (`ls -l`); if missing, build the wasm32 artifacts and reuse the path printed by the build step.","Use the artifact from target/wasm32-unknown-unknown/release/, not target/release/, and prefer absolute paths (or run the CLI from the project root) to avoid cwd-relative misses.","If it exists but still fails, fix permissions/ownership or mount the artifact directory into the container/CI environment."],"exampleFix":"# before\nlinera publish-module --contract contract.wasm --service service.wasm ...\n# fails if run from a dir without those files\n\n# after: build first, publish with the real wasm32 target paths\nlinera publish-module \\\n  --contract target/wasm32-unknown-unknown/release/my_app_contract.wasm \\\n  --service  target/wasm32-unknown-unknown/release/my_app_service.wasm ...","handlingStrategy":"try-catch","validationCode":"fn artifacts_exist(paths: &[&std::path::Path]) -> anyhow::Result<()> {\n    for p in paths {\n        let meta = std::fs::metadata(p)\n            .with_context(|| format!(\"missing artifact {}; run the wasm32 build first\", p.display()))?;\n        anyhow::ensure!(meta.is_file(), \"{} is not a file\", p.display());\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = context.publish_module(chain_client.clone(), contract, service, vm_runtime, formats).await {\n    if e.to_string().contains(\"failed to load contract bytecode\") {\n        eprintln!(\"contract wasm missing — run: cargo build --target wasm32-unknown-unknown --release\");\n    }\n    return Err(e);\n}","preventionTips":["Gate the publish command on an artifacts-exists check for both wasm paths.","Use build scripts (linera build / cargo workspace invocations) that emit the artifact paths and feed them to publish verbatim.","Treat any target/release/*.wasm absence as a signal you built native-only; always build with --target wasm32-unknown-unknown."],"tags":["rust","linera","wasm","file-io","cli"],"backgroundTag":"file-not-found","analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}