{"record":{"id":"f6077f0e7f9bae72","repo":"linera-io/linera-protocol","slug":"failed-to-read-snap-file-path-e","errorCode":null,"errorMessage":"failed to read SNAP file {path:?}: {e}","messagePattern":"failed to read SNAP file (.+?): (.+?)","errorType":"exception","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"linera-client/src/client_context.rs","lineNumber":962,"sourceCode":"                    .map_err(|error| Error::VerifyDataBlob(Box::new(error)))\n            }\n        })\n        .await?;\n\n        info!(\"{}\", \"Data blob verified successfully!\");\n        Ok(())\n    }\n}\n\n/// Reads an insta SNAP file containing a YAML-encoded `Formats` value and parses\n/// it. The caller BCS-serializes the result to obtain the application formats\n/// blob payload: BCS matches the documented intent (the blob is \"the BCS\n/// serialization of an application's `Formats`\") and the encoding the explorer\n/// decodes with.\n#[cfg(feature = \"fs\")]\nfn load_formats_from_snap(path: &std::path::Path) -> Result<linera_sdk::formats::Formats, Error> {\n    let content = fs::read_to_string(path).map_err(|e| {\n        std::io::Error::new(e.kind(), format!(\"failed to read SNAP file {path:?}: {e}\"))\n    })?;\n    let body = strip_snap_frontmatter(&content).ok_or_else(|| {\n        std::io::Error::new(\n            std::io::ErrorKind::InvalidData,\n            format!(\"SNAP file {path:?} is missing the `---` frontmatter delimiters\"),\n        )\n    })?;\n    let formats = serde_yaml_08::from_str(body).map_err(|e| {\n        std::io::Error::new(\n            std::io::ErrorKind::InvalidData,\n            format!(\"failed to parse SNAP body in {path:?} as Formats: {e}\"),\n        )\n    })?;\n    Ok(formats)\n}\n\n#[cfg(feature = \"fs\")]\nfn strip_snap_frontmatter(content: &str) -> Option<&str> {","sourceCodeStart":944,"sourceCodeEnd":980,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-client/src/client_context.rs#L944-L980","documentation":"When publish_module is given a --formats path, load_formats_from_snap reads the file (an insta-style .snap snapshot containing a YAML-encoded Formats value) with fs::read_to_string. This error wraps any read failure with the SNAP path; because read_to_string is used, it also fires for non-UTF-8 bytes (InvalidData). It runs after both bytecode files have loaded successfully.","triggerScenarios":"Calling `linera publish-module ... --formats <path>` where the path is missing, is a directory, lacks read permission, or contains non-UTF-8 content. Typical trigger: passing a path to a .snap snapshot that lives in the application repo's tests/snapshots/ but running the CLI from a checkout that lacks it (or a typo'd filename).","commonSituations":"The .snap file is generated by running the application's test suite (insta snapshots like tests/snapshots/format__format.yaml.snap) and the developer never ran those tests or ran them in a different workspace; CI clones without test artifacts; the file was generated on another branch/version with a different snapshot name; binary or editor-mangled content breaks UTF-8 decoding.","solutions":["Check the path exists and is a regular file (`ls -l`); if the snapshot was never generated, run the app's test suite (e.g. `cargo test` in the application crate) to produce tests/snapshots/*.snap, or copy the .snap from the repo/artifacts that are supposed to contain it.","Match the exact snapshot filename (e.g. format__format.yaml.snap vs format_wrapped_fungible__format_wrapped_fungible.yaml.snap) — use tab-completion or `ls tests/snapshots/` rather than typing it.","If reading a file you edited, ensure it is saved as UTF-8 text without a BOM/binary prefix; fix permissions or mounts if the runtime environment differs from where the file lives."],"exampleFix":"# before\nlinera publish-module ... --formats ./formats.yaml.snap   # file does not exist here\n\n# after: generate or locate the real snapshot, then pass its path\nls examples/fungible/tests/snapshots/   # e.g. format__format.yaml.snap\nlinera publish-module ... --formats examples/fungible/tests/snapshots/format__format.yaml.snap","handlingStrategy":"try-catch","validationCode":"let meta = std::fs::metadata(snap_path)\n    .with_context(|| format!(\"SNAP {snap_path:?} missing; run the app's tests to generate it\"))?;\nanyhow::ensure!(meta.is_file(), \"SNAP {snap_path:?} must be a regular UTF-8 text file\");","typeGuard":null,"tryCatchPattern":"let formats = match load_formats_from_snap(snap_path) {\n    Ok(f) => f,\n    Err(e) if e.to_string().contains(\"failed to read SNAP file\") => {\n        anyhow::bail!(\"cannot read {snap_path:?}: regenerate via `cargo test` or fix the path\")\n    }\n    Err(e) => return Err(e.into()),\n};","preventionTips":["Generate .snap files via the test suite in the same checkout/version you publish from.","Pin exact snapshot filenames in scripts (list tests/snapshots/ first) instead of typing them.","Keep .snap files in version control so CI never depends on a prior local test run."],"tags":["rust","linera","file-io","snapshot","cli"],"backgroundTag":"file-read-failure","analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}