{"record":{"id":"bcc7c75ea03422c6","repo":"Schniz/fnm","slug":"can-t-convert-path-to-string-bcc7c7","errorCode":null,"errorMessage":"Can't convert path to string","messagePattern":"Can't convert path to string","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/shell/windows_cmd/mod.rs","lineNumber":22,"sourceCode":"#[derive(Debug)]\npub struct WindowsCmd;\n\nimpl Shell for WindowsCmd {\n    fn to_clap_shell(&self) -> clap_complete::Shell {\n        // TODO: move to Option\n        panic!(\"Shell completion is not supported for Windows Command Prompt. Maybe try using PowerShell for a better experience?\");\n    }\n\n    fn path(&self, path: &Path) -> anyhow::Result<String> {\n        let current_path =\n            std::env::var_os(\"path\").ok_or_else(|| anyhow::anyhow!(\"Can't read PATH env var\"))?;\n        let mut split_paths: Vec<_> = std::env::split_paths(&current_path).collect();\n        split_paths.insert(0, path.to_path_buf());\n        let new_path = std::env::join_paths(split_paths)\n            .map_err(|err| anyhow::anyhow!(\"Can't join paths: {err}\"))?;\n        let new_path = new_path\n            .to_str()\n            .ok_or_else(|| anyhow::anyhow!(\"Can't convert path to string\"))?;\n        Ok(format!(\"SET PATH={new_path}\"))\n    }\n\n    fn set_env_var(&self, name: &str, value: &str) -> String {\n        format!(\"SET {name}={value}\")\n    }\n\n    fn use_on_cd(&self, config: &crate::config::FnmConfig) -> anyhow::Result<String> {\n        let path = config.base_dir_with_default().join(\"cd.cmd\");\n        create_cd_file_at(&path).map_err(|source| {\n            anyhow::anyhow!(\n                \"Can't create cd.cmd file for use-on-cd at {}: {}\",\n                path.display(),\n                source\n            )\n        })?;\n        let path = path\n            .to_str()","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/Schniz/fnm/blob/86adc9676ceb2a509b21e75e74048b93c89f097d/src/shell/windows_cmd/mod.rs#L4-L40","documentation":"After rejoining the PATH under WindowsCmd, the result must be converted to a `&str` to emit `SET PATH=...`. If the joined PATH contains any non-UTF-8 bytes (from a pre-existing entry), `to_str()` returns None and this anyhow error is produced.","triggerScenarios":"`fnm env --shell cmd` when some existing PATH entry uses a legacy ANSI encoding (non-UTF-8 bytes) so the joined OsString cannot round-trip through Rust's UTF-8 strings.","commonSituations":"Windows profiles where a folder in PATH was created under a non-Unicode code page (e.g. Cyrillic/Shift-JIS CP paths); env vars written by old installers in OEM encoding; batch files saved as ANSI setting PATH entries with accented characters.","solutions":["Inspect PATH entries for garbled characters (`echo %PATH%`); rename the offending folders to ASCII names.","Rebuild PATH from scratch with known-good ASCII entries.","Save any .bat/.cmd scripts that modify PATH as UTF-8 (or plain ASCII).","Enable the Windows UTF-8 system locale option and recreate affected directories."],"exampleFix":":: before\nset PATH=C:\\Users\\<ANSI-garbled>\\bin;%PATH%\nfnm env --shell cmd   :: error: Can't convert path to string\n\n:: after\nset PATH=C:\\Users\\me\\bin;%PATH%\nfnm env --shell cmd   :: ok","handlingStrategy":"validation","validationCode":"fn path_entries_are_utf8() -> bool {\n    std::env::var_os(\"path\")\n        .map(|p| std::env::split_paths(&p).all(|e| e.as_os_str().to_str().is_some()))\n        .unwrap_or(false)\n}","typeGuard":"fn is_utf8_os_string(s: &std::ffi::OsStr) -> bool {\n    s.to_str().is_some()\n}","tryCatchPattern":null,"preventionTips":["Keep PATH entries ASCII/UTF-8; avoid legacy code-page folder names.","Save batch scripts that modify PATH as ASCII or UTF-8.","After locale changes, audit and rebuild PATH."],"tags":["rust","cmd","windows","utf-8","path","fnm-env"],"backgroundTag":"non-utf8-path","analyzedSha":"86adc9676ceb2a509b21e75e74048b93c89f097d","analyzedAt":"2026-08-16T21:43:05.725Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}