{"record":{"id":"fafd99beee7d78cc","repo":"FuelLabs/sway","slug":"error-fafd99","errorCode":null,"errorMessage":"{:?}","messagePattern":"\\{:\\?\\}","errorType":"console","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"forc/src/ops/forc_clean.rs","lineNumber":16,"sourceCode":"use crate::cli::CleanCommand;\nuse anyhow::{anyhow, bail, Result};\nuse forc_pkg::manifest::GenericManifestFile;\nuse forc_pkg::manifest::ManifestFile;\nuse forc_util::default_output_directory;\nuse std::path::PathBuf;\nuse sway_utils::{find_parent_manifest_dir, MANIFEST_FILE_NAME};\n\npub fn clean(command: CleanCommand) -> Result<()> {\n    let CleanCommand { path } = command;\n\n    // find manifest directory, even if in subdirectory\n    let this_dir = if let Some(ref path) = path {\n        PathBuf::from(path)\n    } else {\n        std::env::current_dir().map_err(|e| anyhow!(\"{:?}\", e))?\n    };\n\n    let manifest_dir = match find_parent_manifest_dir(&this_dir) {\n        Some(dir) => dir,\n        None => {\n            bail!(\n                \"could not find `{}` in `{}` or any parent directory\",\n                MANIFEST_FILE_NAME,\n                this_dir.display(),\n            )\n        }\n    };\n    let manifest = ManifestFile::from_dir(manifest_dir)?;\n    // If this is a workspace collect all member paths and clean each of them.\n    let paths: Vec<PathBuf> = match manifest {\n        ManifestFile::Package(_) => std::iter::once(this_dir).collect(),\n        ManifestFile::Workspace(workspace) => workspace.member_paths()?.collect(),\n    };","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/FuelLabs/sway/blob/47e5e902faa42baf652dd6a0c88cd23390c1a614/forc/src/ops/forc_clean.rs#L1-L34","documentation":"forc clean needs a starting directory to search upward for Forc.toml; with no --path flag it calls std::env::current_dir(), and failure (deleted cwd, permission, exotic platform errors) is reported via anyhow!(\"{:?}\", e) — the raw io::Error debug string with no extra context.","triggerScenarios":"Running `forc clean` from a working directory that was deleted out from under the shell (common after `rm -rf` in another terminal or a script that cd's into a dir it then removes), or in environments where cwd cannot be determined.","commonSituations":"Scripts that create, enter, and delete a scratch directory and then invoke forc; container/sandbox setups restricting cwd metadata; shells left in removed directories.","solutions":["cd into an existing directory inside your project and rerun `forc clean`","Pass the project explicitly: `forc clean --path /abs/path/to/project`","Fix the script so forc runs before the directory is removed"],"exampleFix":"# before (cwd deleted)\nforc clean\n\n# after\nforc clean --path /home/me/my-project","handlingStrategy":"validation","validationCode":"fn forc_clean(path: Option<&str>) -> anyhow::Result<()> {\n    let dir = match path {\n        Some(p) => std::path::PathBuf::from(p),\n        None => {\n            let cwd = std::env::current_dir()\n                .map_err(|_| anyhow::anyhow!(\"cwd unavailable; pass --path explicitly\"))?;\n            if !cwd.is_dir() { anyhow::bail!(\"cwd {cwd:?} no longer exists\"); }\n            cwd\n        }\n    };\n    // ... invoke `forc clean --path <dir>`\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["In scripts, invoke `forc clean --path <abs>` instead of relying on the shell's cwd","Order script steps so cleanup happens before the surrounding directory is removed"],"tags":["forc","clean","cwd","environment"],"backgroundTag":null,"analyzedSha":"47e5e902faa42baf652dd6a0c88cd23390c1a614","analyzedAt":"2026-08-16T07:57:45.555Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}