{"record":{"id":"26f4fe86981f1215","repo":"FuelLabs/sway","slug":"failed-to-serialize-lock-file-26f4fe","errorCode":null,"errorMessage":"failed to serialize lock file: {}","messagePattern":"failed to serialize lock file: (.+?)","errorType":"console","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"forc/src/ops/forc_update.rs","lineNumber":55,"sourceCode":"    let manifest = ManifestFile::from_dir(this_dir)?;\n    let lock_path = lock_path(manifest.dir());\n    let old_lock = Lock::from_path(&lock_path).ok().unwrap_or_default();\n    let offline = false;\n    let member_manifests = manifest.member_manifests()?;\n    let ipfs_node = command.ipfs_node.unwrap_or_default();\n    let new_plan = pkg::BuildPlan::from_manifests(&member_manifests, offline, &ipfs_node)?;\n    let new_lock = Lock::from_graph(new_plan.graph());\n    let diff = new_lock.diff(&old_lock);\n    let member_names = member_manifests\n        .values()\n        .map(|manifest| manifest.project.name.clone())\n        .collect();\n    lock::print_diff(&member_names, &diff);\n\n    // If we're not only `check`ing, write the updated lock file.\n    if !check {\n        let string = toml::ser::to_string_pretty(&new_lock)\n            .map_err(|e| anyhow!(\"failed to serialize lock file: {}\", e))?;\n        fs::write(&lock_path, string).map_err(|e| anyhow!(\"failed to write lock file: {}\", e))?;\n        info!(\"   Created new lock file at {}\", lock_path.display());\n    } else {\n        info!(\" `--check` enabled: `Forc.lock` was not changed\");\n    }\n\n    Ok(())\n}\n","sourceCodeStart":37,"sourceCodeEnd":64,"githubUrl":"https://github.com/FuelLabs/sway/blob/47e5e902faa42baf652dd6a0c88cd23390c1a614/forc/src/ops/forc_update.rs#L37-L64","documentation":"After `forc update` recomputes the dependency graph and builds a new Lock from it, the final step serializes with toml::ser::to_string_pretty; failure is wrapped as \"failed to serialize lock file: <error>\". Serialization fails only if the Lock graph contains data not representable in TOML (e.g. invalid string keys/values such as control characters in names), which normally indicates malformed manifest input.","triggerScenarios":"`forc update` (without --check) on a workspace where some dependency name, path-derived key, or version string contains characters TOML cannot represent, or where a partial graph produced inconsistent state.","commonSituations":"Corrupted or hand-edited Forc.toml entries (odd package names/paths), dependencies whose repository-derived identifiers contain unusual characters, or forc bugs after major dependency-handling changes.","solutions":["Back up and delete Forc.lock, then rerun `forc update` to regenerate it from scratch","Inspect member and dependency Forc.toml files for malformed names/paths and fix them","Update forc — serialization failures after dependency-handling refactors are usually fixed in patch releases"],"exampleFix":"# before\nforc update   # failed to serialize lock file: ...\n\n# after\nmv Forc.lock Forc.lock.bak && forc update","handlingStrategy":"fallback","validationCode":"// Before forc update: back up the lock so a serialization failure is recoverable,\n// and sanity-check that member manifests parse.\nstd::fs::copy(\"Forc.lock\", \"Forc.lock.bak\")?;\nfor m in member_manifest_paths() {\n    PackageManifest::from_file(m)\n        .map_err(|e| anyhow::anyhow!(\"malformed manifest {m}: {e}\"))?;\n}","typeGuard":null,"tryCatchPattern":"match run_forc_update(dir) {\n    Ok(()) => Ok(()),\n    Err(e) if e.to_string().contains(\"failed to serialize lock file\") => {\n        // fallback: regenerate the lock from scratch, then retry once\n        std::fs::remove_file(dir.join(\"Forc.lock\")).ok();\n        run_forc_update(dir)\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Keep Forc.lock under version control so a failed update never destroys known-good state","Avoid hand-editing Forc.toml dependency names/paths with unusual characters","After upgrading forc, run `forc update` once in a clean checkout before batch-updating workspaces"],"tags":["forc","update","lock-file","toml-serialization"],"backgroundTag":null,"analyzedSha":"47e5e902faa42baf652dd6a0c88cd23390c1a614","analyzedAt":"2026-08-16T07:57:45.555Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}