{"record":{"id":"a7c18b23a21d2e74","repo":"Schniz/fnm","slug":"can-t-convert-path-to-string-a7c18b","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/fish.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 Fish;\n\nimpl Shell for Fish {\n    fn to_clap_shell(&self) -> clap_complete::Shell {\n        clap_complete::Shell::Fish\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!(\"set -gx PATH {path:?} $PATH;\"))\n    }\n\n    fn set_env_var(&self, name: &str, value: &str) -> String {\n        format!(\"set -gx {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            \"test -f .node-version -o -f .nvmrc -o -f package.json\"\n        } else {\n            \"test -f .node-version -o -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/fish.rs#L1-L36","documentation":"fnm's Fish shell integration builds a `set -gx PATH ...` statement from a `&Path` in `Shell::path`. `Path::to_str()` returns None when the path is not valid UTF-8, and that None becomes this anyhow error. It fires while generating shell setup output such as `fnm env --shell fish`.","triggerScenarios":"Running `fnm env --shell fish` (or any command that renders the Fish PATH line) when the multishell path / fnm base dir contains non-UTF-8 bytes — typically via a polluted FNM_MULTISHELL_PATH, FNM_DIR, or the XDG runtime/temp dir they derive from.","commonSituations":"Fish config files (`config.fish`) saved in a non-UTF-8 encoding setting FNM_DIR; legacy-encoded home or temp directories; XDG_RUNTIME_DIR/XDG_CACHE_HOME containing invalid bytes; multishell dirs left over from a crashed session with mangled names.","solutions":["Check each candidate var: `for v in FNM_DIR FNM_MULTISHELL_PATH XDG_RUNTIME_DIR; printf '%s' \"$$v\" | iconv -f UTF-8 -t UTF-8 >/dev/null || echo \"$v invalid\"; end`.","Reset to safe values: `set -Ux FNM_DIR ~/.local/share/fnm` and `set -e FNM_MULTISHELL_PATH`, then restart the shell.","Ensure LANG/LC_ALL are UTF-8 locales so system tools emit UTF-8 paths.","Clear stale multishell entries under the fnm multishells storage dir and let fnm recreate them."],"exampleFix":"# before\nset -Ux FNM_DIR /mnt/data/bad\\xffpath\nfnm env --shell fish   # error: Can't convert path to string\n\n# after\nset -e FNM_DIR\nset -Ux FNM_DIR ~/.local/share/fnm\nfnm env --shell fish   # set -gx PATH ... emitted","handlingStrategy":"validation","validationCode":"fn fnm_paths_are_utf8() -> bool {\n    [\"FNM_DIR\", \"FNM_MULTISHELL_PATH\", \"XDG_RUNTIME_DIR\", \"XDG_CACHE_HOME\"]\n        .iter()\n        .filter_map(std::env::var_os)\n        .all(|v| v.to_str().is_some())\n}","typeGuard":"fn is_utf8_path(p: &std::path::Path) -> bool {\n    p.to_str().is_some()\n}","tryCatchPattern":"match fish_shell.path(&multishell_dir) {\n    Ok(line) => println!(\"{line}\"),\n    Err(_) => eprintln!(\"fnm env failed; reset FNM_DIR/FNM_MULTISHELL_PATH to UTF-8 paths\"),\n}","preventionTips":["Set FNM_DIR once from a known-good UTF-8 literal in config.fish.","Avoid piping env var values through locale-dependent tools before exporting them.","Periodically prune stale multishell entries so only fnm-created (UTF-8) names exist."],"tags":["rust","path","utf-8","fish","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"}