{"record":{"id":"2a41c061d12b5723","repo":"linera-io/linera-protocol","slug":"error","errorCode":null,"errorMessage":"{}: {error}","messagePattern":"\\{\\}: \\{error\\}","errorType":"exception","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"linera-base/src/data_types.rs","lineNumber":1520,"sourceCode":"pub struct Bytecode {\n    /// Bytes of the bytecode.\n    #[serde(with = \"serde_bytes\")]\n    #[debug(with = \"hex_debug\")]\n    pub bytes: Vec<u8>,\n}\n\nimpl Bytecode {\n    /// Creates a new [`Bytecode`] instance using the provided `bytes`.\n    pub fn new(bytes: Vec<u8>) -> Self {\n        Bytecode { bytes }\n    }\n\n    /// Loads bytecode from a Wasm module file.\n    #[cfg(not(target_arch = \"wasm32\"))]\n    pub async fn load_from_file(path: impl AsRef<std::path::Path>) -> std::io::Result<Self> {\n        let path = path.as_ref();\n        let bytes = tokio::fs::read(path).await.map_err(|error| {\n            std::io::Error::new(error.kind(), format!(\"{}: {error}\", path.display()))\n        })?;\n        Ok(Bytecode { bytes })\n    }\n\n    /// Compresses the [`Bytecode`] into a [`CompressedBytecode`].\n    #[cfg(not(target_arch = \"wasm32\"))]\n    pub fn compress(&self) -> CompressedBytecode {\n        #[cfg(with_metrics)]\n        let _compression_latency = metrics::BYTECODE_COMPRESSION_LATENCY.measure_latency();\n        let compressed_bytes_vec = zstd::stream::encode_all(&*self.bytes, 19)\n            .expect(\"Compressing bytes in memory should not fail\");\n\n        CompressedBytecode {\n            compressed_bytes: Arc::new(compressed_bytes_vec.into_boxed_slice()),\n        }\n    }\n\n    /// Compresses the [`Bytecode`] into a [`CompressedBytecode`].","sourceCodeStart":1502,"sourceCodeEnd":1538,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-base/src/data_types.rs#L1502-L1538","documentation":"Bytecode::load_from_file reads the raw bytes of a Wasm module from disk to build a Bytecode value, which linera-client later uses to publish a module to a chain. Any tokio::fs::read failure is re-wrapped into a new std::io::Error that keeps the original ErrorKind but prepends the failing path. You only see this error when the file at the given path cannot be read at all; malformed Wasm content is not detected here.","triggerScenarios":"Calling Bytecode::load_from_file(path) (directly, or via ClientContext::publish_module with a --contract/--service path) where path does not exist, points to a directory, lacks read permission, or is unreachable (broken symlink, missing mount, wrong container volume). The error kind is NotFound, IsADirectory, PermissionDenied, etc., mirroring the underlying OS error.","commonSituations":"Running `linera publish-module` before building the Wasm artifacts, so target/wasm32-unknown-unknown/release/<app>_{contract,service}.wasm does not exist yet; passing a path from target/release (native build) instead of the wasm32 target dir; relative paths resolved from the wrong working directory; CI or Docker runs where the build output is not mounted into the container.","solutions":["Verify the file exists at the exact path passed: `ls -l <path>`; if missing, build it first with `cargo build --target wasm32-unknown-unknown --release` (or the project's `linera build`) and copy the exact emitted path from the build output.","If the file exists, check it is a regular file with read permission (`file <path>`, `chmod`/`chown` as needed) and that you are running the client from the directory the relative path assumes — or switch to an absolute path.","If building for a different environment, confirm the wasm files were actually produced for wasm32-unknown-unknown (check `target/wasm32-unknown-unknown/release/`) and not overwritten by a native-only build.","In code, pre-check with tokio::fs::metadata / try_exists before loading and fail with a message that includes the build command to run."],"exampleFix":"// before\nlet bytecode = Bytecode::load_from_file(&path).await?; // io error may be path-less in logs upstream\n\n// after\nif !tokio::fs::try_exists(&path).await? {\n    anyhow::bail!(\n        \"bytecode not found at {}: build it first with `cargo build --target wasm32-unknown-unknown --release`\",\n        path.display()\n    );\n}\nlet bytecode = Bytecode::load_from_file(&path).await?;","handlingStrategy":"try-catch","validationCode":"async fn bytecode_readable(path: &std::path::Path) -> std::io::Result<()> {\n    let meta = tokio::fs::metadata(path).await?;\n    if !meta.is_file() {\n        return Err(std::io::Error::new(\n            std::io::ErrorKind::InvalidInput,\n            format!(\"{} is not a regular file\", path.display()),\n        ));\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"match Bytecode::load_from_file(&path).await {\n    Ok(bc) => bc,\n    Err(e) if e.kind() == std::io::ErrorKind::NotFound => {\n        return Err(anyhow::anyhow!(\n            \"bytecode {} not found; build with `cargo build --target wasm32-unknown-unknown --release` first\",\n            path.display()\n        ));\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Always build the wasm32 artifacts before publish and pass the exact paths the build prints.","Script the publish step to assert both artifact paths exist before invoking the client.","Use absolute paths (or a fixed cwd) in CI so relative artifact paths never drift."],"tags":["rust","wasm","file-io","linera","bytecode"],"backgroundTag":"file-not-found","analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}