{"record":{"id":"00700992b4992a48","repo":"FuelLabs/sway","slug":"failed-to-write-toml-file","errorCode":null,"errorMessage":"failed to write toml file: {}","messagePattern":"failed to write toml file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"forc-pkg/src/manifest/dep_modifier.rs","lineNumber":120,"sourceCode":"\n    // write updates to toml doc\n    std::fs::write(&package_manifest_dir, toml_doc.to_string())?;\n\n    let updated_package_manifest = PackageManifestFile::from_file(&package_manifest_dir)?;\n\n    let member_manifests = updated_package_manifest.member_manifests()?;\n\n    let new_plan = pkg::BuildPlan::from_lock_and_manifests(\n        &lock_path,\n        &member_manifests,\n        false,\n        opts.offline,\n        &opts.ipfs_node.clone().unwrap_or_default(),\n    );\n\n    new_plan.or_else(|e| {\n        std::fs::write(&package_manifest_dir, backup_doc.to_string())\n            .map_err(|write_err| anyhow!(\"failed to write toml file: {}\", write_err))?;\n        Err(e)\n    })?;\n\n    if opts.dry_run {\n        info!(\"Dry run enabled. toml file not modified.\");\n        std::fs::write(&package_manifest_dir, backup_doc.to_string())?;\n\n        let string = toml::ser::to_string_pretty(&old_lock)?;\n        std::fs::write(&lock_path, string)?;\n\n        return Ok(());\n    }\n\n    Ok(())\n}\n\nfn resolve_package_path(\n    manifest_file: &ManifestFile,","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/FuelLabs/sway/blob/47e5e902faa42baf652dd6a0c88cd23390c1a614/forc-pkg/src/manifest/dep_modifier.rs#L102-L138","documentation":"In forc's dependency add/remove flow (DepModifier), Forc.toml is modified in memory and then validated by rebuilding a BuildPlan; if that validation fails, the tool restores the original Forc.toml from its in-memory backup. This error is the restore write failing - so when you see it, two things went wrong: the modified manifest was invalid (the original error) AND the filesystem prevented rollback (the wrapped write_err). The underlying plan error is masked by this one.","triggerScenarios":"forc add / forc remove where BuildPlan::from_lock_and_manifests rejects the modified manifest and the subsequent fs::write of the backup Forc.toml fails - read-only project directory, deleted parent directory, changed permissions, or a full disk.","commonSituations":"Read-only or root-owned checkouts in CI containers; disk-full conditions; directories removed by another process mid-command; running without write permission on the project.","solutions":["Restore Forc.toml manually - the backup content equals the original, or use git checkout -- Forc.toml / git restore Forc.toml.","Fix filesystem writability (permissions, mount options, disk space) in the project directory.","Re-run the forc add/remove command; with rollback now working you will see the real underlying plan error and can fix the dependency spec that caused it.","Use --dry-run first to validate a dependency change without modifying files."],"exampleFix":"# before: run where Forc.toml is not writable\n$ chmod 444 Forc.toml && forc add foo\n# error: failed to write toml file ...\n\n# after\n$ chmod 644 Forc.toml\n$ git restore Forc.toml   # undo any partial change\n$ forc add foo            # real validation error (if any) now visible","handlingStrategy":"try-catch","validationCode":"// Before running forc add/remove, assert the project dir is writable:\nuse std::fs;\nfn writable_dir(p: &std::path::Path) -> bool {\n    fs::OpenOptions::new().write(true).open(p.join(\".writetest\".as_path()))\n        .map(|f| { drop(f); fs::remove_file(p.join(\".writetest\")).ok(); true })\n        .unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"// The API returns anyhow::Result - handle Err and restore yourself, since the tool's\n// own rollback may be what failed:\nmatch modify_deps(opts) {\n    Ok(_) => {}\n    Err(e) => {\n        if e.to_string().contains(\"failed to write toml file\") {\n            let _ = std::process::Command::new(\"git\")\n                .args([\"restore\", \"Forc.toml\"]).status();\n        }\n    }\n}","preventionTips":["Run forc add/remove only in writable checkouts; fix chmod/ownership first.","Prefer --dry-run to validate dependency changes before touching files.","Keep the project under git so a failed rollback is always recoverable.","On this error, always restore Forc.toml manually and retry to unmask the real cause."],"tags":["forc","forc-pkg","manifest","filesystem","rollback"],"backgroundTag":null,"analyzedSha":"47e5e902faa42baf652dd6a0c88cd23390c1a614","analyzedAt":"2026-08-16T07:57:45.555Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}