{"record":{"id":"491c4ac2ca87519d","repo":"wasmerio/wasmer","slug":"no-current-dir-name","errorCode":null,"errorMessage":"no current dir name","messagePattern":"no current dir name","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/cli/src/commands/init.rs","lineNumber":213,"sourceCode":"        Ok(())\n    }\n\n    fn target_file(&self) -> Result<(String, PathBuf), anyhow::Error> {\n        match self.out.as_ref() {\n            None => {\n                let current_dir = std::env::current_dir()?;\n                let package_name = self\n                    .package_name\n                    .clone()\n                    .or_else(|| {\n                        current_dir\n                            .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 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)))","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/wasmerio/wasmer/blob/8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5/lib/cli/src/commands/init.rs#L195-L231","documentation":"In `wasmer init`'s `target_file` helper, when no target directory argument is given the CLI derives the package name from the current directory's canonicalized file stem. This error is raised when that derivation fails — canonicalization failed, the path has no file stem, or the stem is not valid UTF-8 — so no package name can be inferred.","triggerScenarios":"Running `wasmer init` (without a name/dir argument and without --package-name) from a directory whose canonical path cannot be resolved or whose file stem is missing/non-UTF-8, e.g. the cwd was deleted and recreated, or the path contains invalid UTF-8 bytes.","commonSituations":"Working from a deleted-then-recreated directory (stale cwd handle); non-UTF-8 directory names on Linux; invoking init in a context where canonicalize fails (broken mount, permission issue on a parent).","solutions":["Pass an explicit directory/package name: `wasmer init my-app` so the name is not inferred.","Or supply `--package-name <name>` to skip directory-based inference.","`cd` out and back into the directory (or reopen the shell) to refresh a stale cwd, then retry.","Rename the directory to a UTF-8, stem-bearing name if it has invalid bytes or an odd path shape."],"exampleFix":"// before (cwd unresolvable)\nwasmer init  // no current dir name\n// after\nwasmer init my-app","handlingStrategy":"validation","validationCode":"fn can_infer_pkg_name_from_cwd() -> bool {\n    std::env::current_dir()\n        .ok()\n        .and_then(|d| d.canonicalize().ok())\n        .and_then(|d| d.file_stem().map(|_| ()))\n        .is_some()\n}\n// before `wasmer init` with no args:\nassert!(can_infer_pkg_name_from_cwd(), \"pass a name or --package-name\");","typeGuard":"fn has_valid_stem(p: &std::path::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_cmd.run_async().await {\n    Err(e) if e.to_string().contains(\"no current dir name\") => {\n        eprintln!(\"Pass an explicit name: wasmer init my-app\");\n    }\n    other => other?,\n}","preventionTips":["Always pass an explicit name or --package-name in scripts and CI.","Avoid running init from deleted/recreated directories; `cd` out and back.","Use UTF-8 directory names without odd path components."],"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"}