{"record":{"id":"1fdc521b9ed6ce43","repo":"wasmerio/wasmer","slug":"no-dir-name","errorCode":null,"errorMessage":"no dir name","messagePattern":"no dir name","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/cli/src/commands/init.rs","lineNumber":230,"sourceCode":"                    })\n                    .ok_or_else(|| anyhow::anyhow!(\"no current dir name\"))?;\n                Ok((package_name, current_dir.join(WASMER_TOML_NAME)))\n            }\n            Some(s) => {\n                std::fs::create_dir_all(s)\n                    .map_err(|e| anyhow::anyhow!(\"{e}\"))\n                    .with_context(|| anyhow::anyhow!(\"{}\", s.display()))?;\n                let package_name = self\n                    .package_name\n                    .clone()\n                    .or_else(|| {\n                        s.canonicalize()\n                            .ok()?\n                            .file_stem()\n                            .and_then(|s| s.to_str())\n                            .map(|s| s.to_string())\n                    })\n                    .ok_or_else(|| anyhow::anyhow!(\"no dir name\"))?;\n                Ok((package_name, s.join(WASMER_TOML_NAME)))\n            }\n        }\n    }\n\n    fn get_filesystem_mapping(include: &[String]) -> impl Iterator<Item = (String, PathBuf)> + '_ {\n        include.iter().map(|path| {\n            if path == \".\" || path == \"/\" {\n                return (\"/\".to_string(), Path::new(\"/\").to_path_buf());\n            }\n\n            let key = format!(\"./{path}\");\n            let value = PathBuf::from(format!(\"/{path}\"));\n\n            (key, value)\n        })\n    }\n","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/wasmerio/wasmer/blob/8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5/lib/cli/src/commands/init.rs#L212-L248","documentation":"In `wasmer init`'s `target_file`, when a target directory `Some(s)` is given and no explicit package name was passed, the CLI derives the package name from `s.canonicalize().file_stem()`. This error is raised when that inference fails — canonicalization fails, there is no file stem, or the stem is not valid UTF-8.","triggerScenarios":"Running `wasmer init <dir>` without `--package-name` where the directory path cannot be canonicalized or has no valid UTF-8 file stem (e.g. dir is `/` or `.` resolving to a stem-less path, non-UTF-8 bytes in the name, dir not yet existing under a broken mount).","commonSituations":"Passing odd targets like `/`, `.`, or paths ending in `..`; non-UTF-8 directory names; canonicalization failing due to symlinks into unavailable mounts; forgetting `--package-name` when using unusual paths.","solutions":["Provide the name explicitly: `wasmer init <dir> --package-name <name>`.","Use a normal directory name (UTF-8, not `/` or `.`) so the stem can be inferred.","Ensure the target path fully exists and is reachable (create parents first, fix symlinks).","Retry from a shell where the path resolves normally (no broken mounts)."],"exampleFix":"// before\nwasmer init /  // no dir name\n// after\nwasmer init / --package-name my-package","handlingStrategy":"validation","validationCode":"fn stem_of(target: &Path) -> Option<String> {\n    target.canonicalize().ok()\n        .and_then(|c| c.file_stem().and_then(|s| s.to_str()))\n        .map(|s| s.to_string())\n}\n// fall back if inference would fail:\nlet name = stem_of(dir).unwrap_or_else(|| \"my-package\".into());","typeGuard":"fn stem_is_inferable(p: &Path) -> bool {\n    p.canonicalize().ok()\n        .and_then(|c| c.file_stem().and_then(|s| s.to_str()).map(|_| ()))\n        .is_some()\n}","tryCatchPattern":"match init_in(dir).await {\n    Err(e) if e.to_string().contains(\"no dir name\") => {\n        eprintln!(\"Supply --package-name; cannot infer from {:?}\", dir);\n    }\n    other => other?,\n}","preventionTips":["Pass --package-name whenever the target path is unusual (`/`, `.`, `..`).","Use plain UTF-8 directory names for init targets.","Ensure the target fully exists (create parents) so canonicalize succeeds."],"tags":["cli","filesystem","package-init"],"backgroundTag":"cannot-infer-package-name","analyzedSha":"8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5","analyzedAt":"2026-09-01T23:06:31.009Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}