{"record":{"id":"c2bd1170ef0509cd","repo":"linera-io/linera-protocol","slug":"failed-to-load-service-bytecode-from-service","errorCode":null,"errorMessage":"failed to load service bytecode from {service:?}: {e}","messagePattern":"failed to load service bytecode from (.+?): (.+?)","errorType":"exception","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"linera-client/src/client_context.rs","lineNumber":860,"sourceCode":"impl<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(\n            contract_bytecode,\n            service_bytecode,\n            vm_runtime,\n            formats_bytes,\n        )\n        .await;","sourceCodeStart":842,"sourceCodeEnd":878,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-client/src/client_context.rs#L842-L878","documentation":"ClientContext::publish_module loads the service half of an application from the --service path using Bytecode::load_from_file; this branch re-wraps the I/O failure with the specific service path. It only runs after the contract bytecode loaded successfully, so seeing this error means --contract was fine and --service was not. Like its contract twin, it preserves the underlying io::ErrorKind.","triggerScenarios":"Calling publish_module where the --service path is missing, unreadable, or a directory — typically because the service .wasm was never built or has a different filename than the contract artifact (e.g. <app>_service.wasm vs <app>_contract.wasm) and the wrong name was passed.","commonSituations":"The contract artifact exists but the service artifact was skipped (partial build, cleaned target, feature-gated service crate not built); filename typo (missing _service suffix); renaming the crate without updating the publish command; copying only one artifact into a Docker/CI stage.","solutions":["Verify the exact --service path exists (`ls -l`); confirm the service artifact name matches the crate (<crate>_service.wasm) under target/wasm32-unknown-unknown/release/.","Rebuild both artifacts together (cargo build --target wasm32-unknown-unknown --release or `linera build`) so contract and service stay in sync, then republish with both fresh paths.","Check permissions/mounts if the file is present in the builder but absent in the runtime environment."],"exampleFix":"# before\nlinera publish-module \\\n  --contract target/wasm32-unknown-unknown/release/my_app_contract.wasm \\\n  --service  target/wasm32-unknown-unknown/release/my_app.wasm ...   # wrong name -> this error\n\n# after\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":"let (contract, service) = (contract_path.as_path(), service_path.as_path());\nfor p in [contract, service] {\n    if !p.is_file() {\n        anyhow::bail!(\"artifact {} not found; build both wasm modules first\", p.display());\n    }\n}","typeGuard":null,"tryCatchPattern":"match context.publish_module(chain_client.clone(), contract, service, vm_runtime, formats).await {\n    Ok(id) => id,\n    Err(e) if e.to_string().contains(\"failed to load service bytecode\") => {\n        anyhow::bail!(\"service wasm at {service:?} missing — rebuild both artifacts and retry\")\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always build contract and service artifacts in one command so they stay paired.","Name-check the _service.wasm suffix when scripting; most misses are the wrong filename, not a failed build.","Assert file sizes are non-zero — a half-written artifact passes an existence check but fails downstream."],"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"}