{"record":{"id":"fa096f303b6b8b82","repo":"FuelLabs/sway","slug":"failed-to-read","errorCode":null,"errorMessage":"failed to read {}: {}","messagePattern":"failed to read (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"forc-pkg/src/lock.rs","lineNumber":157,"sourceCode":"    pub fn name_disambiguated(&self, disambiguate: &HashSet<&str>) -> Cow<str> {\n        let disambiguate = disambiguate.contains(&self.name[..]);\n        pkg_name_disambiguated(&self.name, &self.source, disambiguate)\n    }\n}\n\n/// Represents a `DepKind` before getting parsed.\n///\n/// Used to carry on the type of the `DepKind` until parsing. After parsing pkg_dep_line converted into `DepKind`.\nenum UnparsedDepKind {\n    Library,\n    Contract,\n}\n\nimpl Lock {\n    /// Load the `Lock` structure from the TOML `Forc.lock` file at the specified path.\n    pub fn from_path(path: &Path) -> Result<Self> {\n        let string = fs::read_to_string(path)\n            .map_err(|e| anyhow!(\"failed to read {}: {}\", path.display(), e))?;\n        toml::de::from_str(&string).map_err(|e| anyhow!(\"failed to parse lock file: {}\", e))\n    }\n\n    /// Given a graph of pinned packages, create a `Lock` representing the `Forc.lock` file\n    /// structure.\n    pub fn from_graph(graph: &pkg::Graph) -> Self {\n        let names = graph.node_indices().map(|n| &graph[n].name[..]);\n        let disambiguate: HashSet<_> = names_requiring_disambiguation(names).collect();\n        // Collect the packages.\n        let package: BTreeSet<_> = graph\n            .node_indices()\n            .map(|node| PkgLock::from_node(graph, node, &disambiguate))\n            .collect();\n        Self { package }\n    }\n\n    /// Given a `Lock` loaded from a `Forc.lock` file, produce the graph of pinned dependencies.\n    pub fn to_graph(&self) -> Result<pkg::Graph> {","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/FuelLabs/sway/blob/47e5e902faa42baf652dd6a0c88cd23390c1a614/forc-pkg/src/lock.rs#L139-L175","documentation":"Lock::from_path loads Forc.lock with fs::read_to_string; failure at that I/O stage is wrapped with the offending path. The file was not read at all - missing, permission denied, path is a directory, or non-UTF-8 bytes. It is deliberately distinct from the 'failed to parse lock file' TOML error raised on the next line for content problems.","triggerScenarios":"Calling Lock::from_path (directly or via forc-pkg flows such as BuildPlan::from_lock_and_manifests) where no Forc.lock exists yet, is unreadable, or contains non-UTF-8 bytes.","commonSituations":"First build in a fresh clone before lock generation; deleted or moved lock file; restrictive permissions or read-only mounts in CI; a binary/corrupted lock file; concurrent forc processes rewriting Forc.lock mid-read.","solutions":["Verify the path: Forc.lock must exist next to Forc.toml in the project directory you are operating on.","Run forc build once to generate the lock file before invoking APIs that load it.","Fix permissions or remount read-only filesystems so the file is readable by the current user.","If the file is corrupted or non-UTF-8, delete it and re-resolve dependencies with a fresh build."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Rust, before calling Lock::from_path:\nuse std::fs;\nfn lock_readable(p: &std::path::Path) -> bool {\n    match fs::metadata(p) {\n        Ok(m) => m.is_file() && fs::read(p).map(|b| String::from_utf8(b).is_ok()).unwrap_or(false),\n        Err(_) => false,\n    }\n}\nif !lock_readable(&lock_path) { /* generate lock via forc build instead of failing */ }","typeGuard":null,"tryCatchPattern":"// Lock::from_path returns anyhow::Result - match and special-case I/O kinds:\nmatch Lock::from_path(&path) {\n    Ok(lock) => { /* ... */ }\n    Err(e) if e.to_string().starts_with(\"failed to read\") => {\n        // treat as 'lock missing/unreadable': regenerate rather than abort\n    }\n    Err(e) => { /* parse error - regenerate or surface */ }\n}","preventionTips":["Run one forc build in fresh clones so Forc.lock exists before tooling reads it.","Do not delete or relocate Forc.lock independently of Forc.toml.","Keep lock files UTF-8 text and readable in CI images.","Treat lock read failures as a signal to re-resolve, not to hand-craft the file."],"tags":["forc","forc-pkg","lockfile","io"],"backgroundTag":null,"analyzedSha":"47e5e902faa42baf652dd6a0c88cd23390c1a614","analyzedAt":"2026-08-16T07:57:45.555Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}