{"record":{"id":"842fb350bb2f94ef","repo":"wasmerio/wasmer","slug":"cannot-pre-open-the-current-directory-twice-vo","errorCode":null,"errorMessage":"Cannot pre-open the current directory twice: '--volume=.' must only be specified once","messagePattern":"Cannot pre-open the current directory twice: '--volume=\\.' must only be specified once","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/cli/src/commands/run/wasi.rs","lineNumber":510,"sourceCode":"            let resolved_host = host.canonicalize().with_context(|| {\n                format!(\n                    \"could not canonicalize path for argument '--volume {}:{}'\",\n                    host.display(),\n                    guest,\n                )\n            })?;\n\n            if guest == \"/\" && is_wasix {\n                // Note: it appears we canonicalize the path before this point and showing the value of\n                // `host` in the error message may throw users off, so we use a placeholder.\n                tracing::warn!(\n                    \"Mounting on the guest's virtual root with --volume <HOST_DIR>:/ breaks WASIX modules' filesystems\"\n                );\n            }\n\n            let mapping = if guest == \".\" {\n                if have_current_dir {\n                    bail!(\n                        \"Cannot pre-open the current directory twice: '--volume=.' must only be specified once\"\n                    );\n                }\n                have_current_dir = true;\n\n                let host = if host == Path::new(\".\") {\n                    std::env::current_dir().context(\"could not determine current directory\")?\n                } else {\n                    host.clone()\n                };\n                MappedDirectory {\n                    host: resolved_host,\n                    guest: if is_wasix {\n                        MAPPED_CURRENT_DIR_DEFAULT_PATH.to_string()\n                    } else {\n                        \"/\".to_string()\n                    },\n                }","sourceCodeStart":492,"sourceCodeEnd":528,"githubUrl":"https://github.com/wasmerio/wasmer/blob/8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5/lib/cli/src/commands/run/wasi.rs#L492-L528","documentation":"build_mapped_directories tracks whether the guest's current directory ('.') has already been pre-opened. Each --volume mapping with guest path '.' pre-opens the host directory as the guest root of the current dir; doing it twice would create two conflicting mappings for the same guest path, so the second one is rejected.","triggerScenarios":"Specifying `--volume .` or `--volume=<HOST>:.` (guest path \".\") more than once in a single wasmer run invocation while building mapped dirs in prepare().","commonSituations":"Shell scripts that append --volume flags from multiple config sources (env var + config file), each adding '.'; copy-pasting volume flags from different examples; wrapping wasmer where defaults already pre-open '.' and the user adds another.","solutions":["Remove the duplicate --volume=. mapping, keeping only one","Merge duplicated volume flags from script/config sources into a single occurrence","If you need extra host dirs, map them to distinct guest paths (e.g. --volume=/data:/data) instead of '.'"],"exampleFix":"// before\nwasmer run app.wasm --volume . --volume ~/data:.\n// after\nwasmer run app.wasm --volume . --volume ~/data:/data","handlingStrategy":"validation","validationCode":"fn validate_volumes(volumes: &[String]) -> Result<(), String> {\n    let count = volumes.iter().filter(|v| {\n        let guest = v.split(':').nth(1).unwrap_or(v);\n        guest == \".\"\n    }).count();\n    if count > 1 { Err(\"'--volume=.' may only be specified once\".into()) } else { Ok(()) }\n}","typeGuard":"fn maps_current_dir(vol: &str) -> bool {\n    let guest = vol.splitn(2, ':').nth(1).unwrap_or(vol);\n    guest == \".\"\n}","tryCatchPattern":"match wasmer_run_with_volumes(&volumes) {\n    Err(e) if e.to_string().contains(\"Cannot pre-open the current directory twice\") => {\n        let deduped = dedupe_dot_volumes(&volumes);\n        wasmer_run_with_volumes(&deduped)\n    }\n    other => other,\n}","preventionTips":["Deduplicate --volume flags collected from multiple config sources","Map additional host dirs to unique guest paths instead of '.'","Centralize volume construction in one function rather than appending flags ad hoc"],"tags":["cli","wasi","filesystem","duplicate-argument"],"backgroundTag":"duplicate-path-mapping","analyzedSha":"8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5","analyzedAt":"2026-09-01T23:06:31.009Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}