{"record":{"id":"3d08f885d1bbe06f","repo":"FuelLabs/sway","slug":"invalid-lock","errorCode":null,"errorMessage":"Invalid lock: {}","messagePattern":"Invalid lock: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"forc-pkg/src/pkg.rs","lineNumber":695,"sourceCode":"    ) -> Result<Self> {\n        // Check toolchain version\n        validate_version(manifests)?;\n        // Keep track of the cause for the new lock file if it turns out we need one.\n        let mut new_lock_cause = None;\n\n        // First, attempt to load the lock.\n        let lock = Lock::from_path(lock_path).unwrap_or_else(|e| {\n            new_lock_cause = if e.to_string().contains(\"No such file or directory\") {\n                Some(anyhow!(\"lock file did not exist\"))\n            } else {\n                Some(e)\n            };\n            Lock::default()\n        });\n\n        // Next, construct the package graph from the lock.\n        let mut graph = lock.to_graph().unwrap_or_else(|e| {\n            new_lock_cause = Some(anyhow!(\"Invalid lock: {}\", e));\n            Graph::default()\n        });\n\n        // Since the lock file was last created there are many ways in which it might have been\n        // invalidated. E.g. a package's manifest `[dependencies]` table might have changed, a user\n        // might have edited the `Forc.lock` file when they shouldn't have, a path dependency no\n        // longer exists at its specified location, etc. We must first remove all invalid nodes\n        // before we can determine what we need to fetch.\n        let invalid_deps = validate_graph(&graph, manifests)?;\n        let members: HashSet<String> = manifests.keys().cloned().collect();\n        remove_deps(&mut graph, &members, &invalid_deps);\n\n        // We know that the remaining nodes have valid paths, otherwise they would have been\n        // removed. We can safely produce an initial `manifest_map`.\n        let mut manifest_map = graph_to_manifest_map(manifests, &graph)?;\n\n        // Attempt to fetch the remainder of the graph.\n        let _added = fetch_graph(manifests, offline, ipfs_node, &mut graph, &mut manifest_map)?;","sourceCodeStart":677,"sourceCodeEnd":713,"githubUrl":"https://github.com/FuelLabs/sway/blob/47e5e902faa42baf652dd6a0c88cd23390c1a614/forc-pkg/src/pkg.rs#L677-L713","documentation":"Recorded when the Forc.lock file could be found but lock.to_graph() failed; the {} is the graph-construction error (malformed package entries, unresolvable references, bad pinned sources). Like other lock causes, forc recovers by discarding the graph and regenerating the lock - fatal only under --locked.","triggerScenarios":"Hand-edited Forc.lock introducing schema violations; a lock produced by a much older/newer forc with an incompatible schema; a git merge conflict on Forc.lock resolved by keeping fragments of both sides; truncated file.","commonSituations":"Branch merges that conflict on Forc.lock; upgrading forc versions and reusing an old lock; manually pinning git commits by editing the lock.","solutions":["Delete Forc.lock and rebuild without --locked to regenerate it, then commit.","Prefer 'forc update' or editing Forc.toml dependencies over hand-editing the lock.","If it persists on a freshly generated lock, check for forc version mismatch between contributors (pinned toolchain in fuel-toolchain.toml)."],"exampleFix":"# before\nforc build --locked   # Invalid lock: ...\n\n# after\nrm Forc.lock\nforc build && git add Forc.lock && git commit -m \"chore: regenerate Forc.lock\"\nforc build --locked","handlingStrategy":"fallback","validationCode":"// pre-verify the lock can round-trip into a graph\nuse forc_pkg::lock::Lock;\nif Lock::from_path(lock_path.as_ref()).and_then(|l| l.to_graph()).is_err() {\n    // lock is unusable: plan to regenerate instead of failing the build\n}","typeGuard":null,"tryCatchPattern":"match Lock::from_path(lock_path.as_ref()).and_then(|l| l.to_graph()) {\n    Ok(graph) => use_graph(graph),\n    Err(_) => {\n        // fall back: discard the corrupt lock exactly once and rebuild\n        let _ = std::fs::remove_file(&lock_path);\n        rebuild_and_regenerate_lock()?;\n    }\n}","preventionTips":["Never hand-edit Forc.lock; change dependencies in Forc.toml and regenerate.","Resolve git merge conflicts on Forc.lock by regenerating, not by merging text.","Pin the forc version across the team (fuel-toolchain.toml) to keep the lock schema stable."],"tags":["lock-file","corruption","forc","versioning"],"backgroundTag":null,"analyzedSha":"47e5e902faa42baf652dd6a0c88cd23390c1a614","analyzedAt":"2026-08-16T07:57:45.555Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}