{"record":{"id":"234eff3c032c6a48","repo":"Schniz/fnm","slug":"can-t-convert-path-to-string","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/bash.rs","lineNumber":18,"sourceCode":"use crate::version_file_strategy::VersionFileStrategy;\n\nuse super::shell::Shell;\nuse indoc::formatdoc;\nuse std::path::Path;\n\n#[derive(Debug)]\npub struct Bash;\n\nimpl Shell for Bash {\n    fn to_clap_shell(&self) -> clap_complete::Shell {\n        clap_complete::Shell::Bash\n    }\n\n    fn path(&self, path: &Path) -> anyhow::Result<String> {\n        let path = path\n            .to_str()\n            .ok_or_else(|| anyhow::anyhow!(\"Can't convert path to string\"))?;\n        let path =\n            super::windows_compat::maybe_fix_windows_path(path).unwrap_or_else(|| path.to_string());\n        Ok(format!(\"export PATH={path:?}:\\\"$PATH\\\"\"))\n    }\n\n    fn set_env_var(&self, name: &str, value: &str) -> String {\n        format!(\"export {name}={value:?}\")\n    }\n\n    fn use_on_cd(&self, config: &crate::config::FnmConfig) -> anyhow::Result<String> {\n        let version_file_exists_condition = if config.resolve_engines() {\n            \"-f .node-version || -f .nvmrc || -f package.json\"\n        } else {\n            \"-f .node-version || -f .nvmrc\"\n        };\n        let autoload_hook = match config.version_file_strategy() {\n            VersionFileStrategy::Local => formatdoc!(\n                r\"","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/Schniz/fnm/blob/86adc9676ceb2a509b21e75e74048b93c89f097d/src/shell/bash.rs#L1-L36","documentation":"fnm's Bash shell integration builds an `export PATH=...` line from a `&Path` (the multishell symlink directory) in `Shell::path`. It calls `Path::to_str()`, which returns None when the path holds bytes that are not valid UTF-8, and converts that None into an anyhow error with this message. It surfaces from commands that emit shell setup, primarily `fnm env --shell bash` and `fnm use`.","triggerScenarios":"Running `fnm env --shell bash` (or any flow that renders the Bash PATH export) when the path involved — FNM_MULTISHELL_PATH, FNM_DIR, or the temp/multishell storage dir derived from them — contains invalid UTF-8 bytes.","commonSituations":"FNM_DIR or FNM_MULTISHELL_PATH exported from a script saved in a legacy code page; a Unix username or /tmp path with non-UTF-8 bytes (e.g. Latin-1 or Shift-JIS filenames); paths mangled by backup/restore tools; env vars set with raw bytes via `export FNM_DIR=$'\\xff...'`.","solutions":["Verify the suspect env var is valid UTF-8: `printf '%s' \"$FNM_DIR\" | iconv -f UTF-8 -t UTF-8 >/dev/null || echo invalid` (repeat for FNM_MULTISHELL_PATH and TMPDIR).","Point FNM_DIR at a clean ASCII/UTF-8 path: `export FNM_DIR=\"$HOME/.fnm\"` and unset the broken FNM_MULTISHELL_PATH.","Fix the locale (LANG/LC_ALL=en_US.UTF-8) so dependent tools stop producing non-UTF-8 names, then recreate the multishell dir by opening a new shell.","If a username/home dir itself is non-UTF-8, relocate fnm storage with `--fnm-dir` to an ASCII path."],"exampleFix":"# before\nexport FNM_DIR=$'/tmp/bad\\xffdir'\nfnm env --shell bash   # error: Can't convert path to string\n\n# after\nunset FNM_DIR\nexport FNM_DIR=\"$HOME/.local/share/fnm\"\nfnm env --shell bash   # export PATH=... emitted","handlingStrategy":"validation","validationCode":"fn fnm_paths_are_utf8() -> bool {\n    [\"FNM_DIR\", \"FNM_MULTISHELL_PATH\", \"TMPDIR\"]\n        .iter()\n        .filter_map(std::env::var_os)\n        .all(|v| v.to_str().is_some())\n}\n// run before invoking `fnm env --shell bash`; abort with a clear message if false","typeGuard":"fn is_utf8_path(p: &std::path::Path) -> bool {\n    p.to_str().is_some()\n}","tryCatchPattern":"match bash_shell.path(&multishell_dir) {\n    Ok(line) => println!(\"{line}\"),\n    Err(e) if e.to_string().contains(\"convert path to string\") =>\n        eprintln!(\"fnm dir is not valid UTF-8; check FNM_DIR / FNM_MULTISHELL_PATH\"),\n    Err(e) => return Err(e),\n}","preventionTips":["Keep FNM_DIR, FNM_MULTISHELL_PATH and temp dirs on ASCII-named paths.","Save shell rc files that export fnm variables as UTF-8.","Validate env-derived paths with iconv (or Path::to_str) in bootstrap scripts before calling fnm."],"tags":["rust","path","utf-8","bash","fnm-env","anyhow"],"backgroundTag":"non-utf8-path","analyzedSha":"86adc9676ceb2a509b21e75e74048b93c89f097d","analyzedAt":"2026-08-16T21:43:05.725Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}