{"record":{"id":"7f0aa462fe6a21fa","repo":"libnyanpasu/clash-nyanpasu","slug":"config-path-is-not-utf-8","errorCode":null,"errorMessage":"config path is not UTF-8: {}","messagePattern":"config path is not UTF-8: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/tauri/src/client/mod.rs","lineNumber":1340,"sourceCode":"    pub async fn rebuild_running_config(&self) -> Result<()> {\n        self.reconcile_core()\n            .await\n            .map_err(client_error_from_core)?;\n        self.inner.ui_sink.refresh_clash();\n        Ok(())\n    }\n\n    pub(crate) async fn regenerate_runtime(&self) -> Result<()> {\n        self.reconcile_core()\n            .await\n            .map(|_| ())\n            .map_err(client_error_from_core)\n    }\n}\n\nfn utf8_path(path: PathBuf) -> anyhow::Result<Utf8PathBuf> {\n    Utf8PathBuf::from_path_buf(path)\n        .map_err(|path| anyhow::anyhow!(\"config path is not UTF-8: {}\", path.display()))\n}\n\n#[cfg(test)]\npub(crate) mod tests {\n    use super::*;\n    use crate::state::{\n        mirror::{\n            ClashLegacyBridge, NoopPreparedLegacyMirror, PreparedLegacyMirror, VergeLegacyBridge,\n            WindowLegacyBridge,\n        },\n        profiles::ports::{\n            CleanupOutcome, MaterializationReconcileReport, MockProfileFsPort,\n            MockProfileMaterializationPort, MockRebuildNotifier, MockSubscriptionFetcher,\n            PreparedCleanup, PreparedMaterialization, ProfileMaterializationPort,\n        },\n    };\n    use camino::Utf8PathBuf;\n    use nyanpasu_config::{","sourceCodeStart":1322,"sourceCodeEnd":1358,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/client/mod.rs#L1322-L1358","documentation":"This error is thrown by `utf8_path` when converting a `PathBuf` into `Utf8PathBuf` fails, i.e. the config file path contains bytes that are not valid UTF-8. On Windows, paths are UTF-16 and may contain unpaired surrogates; on Unix they may be arbitrary bytes. The client requires UTF-8 paths because config paths are passed through typed `Utf8PathBuf` values (serde/IPC-friendly).","triggerScenarios":"Calling any client config API (e.g. loading/patching a config file at backend/tauri/src/client/mod.rs:1340) where the resolved config path was constructed from an environment with non-UTF-8 characters — e.g. a user profile directory, home dir, or `--config` argument containing legacy-encoded bytes.","commonSituations":"Windows usernames or home directories with characters outside the system's UTF-8 conversion (CJK/emoji/legacy codepage names); Linux systems with filenames in non-UTF-8 locale encodings; paths built from raw OS strings read from the environment.","solutions":["Rename the config directory/file (or the user profile path) so it contains only valid UTF-8 characters","Check the path with `Path::to_str()` before calling the API to detect the offending bytes","Re-encode/recover the path via `String::from_utf8` on the raw bytes to find which component is invalid","If on Windows, ensure the path is retrieved via UTF-8-safe APIs (`to_string_lossy` only masks the problem)"],"exampleFix":"// before\nlet path = std::env::var(\"CONFIG_PATH\").unwrap(); // may carry non-UTF-8 bytes on some platforms\nclient.load_config(PathBuf::from(path)).await?;\n// after\nlet path = std::env::var_os(\"CONFIG_PATH\").unwrap();\nif path.to_str().is_none() {\n    eprintln!(\"CONFIG_PATH is not valid UTF-8: {:?}\", path);\n    return;\n}\nclient.load_config(PathBuf::from(path)).await?;","handlingStrategy":"validation","validationCode":"fn ensure_utf8(path: &std::path::Path) -> Result<(), String> {\n    match path.to_str() {\n        Some(_) => Ok(()),\n        None => Err(format!(\"path is not valid UTF-8: {:?}\", path.as_os_str())),\n    }\n}","typeGuard":"fn is_utf8_path(path: &std::path::Path) -> bool {\n    path.to_str().is_some()\n}","tryCatchPattern":null,"preventionTips":["Always resolve config paths through UTF-8-checked APIs before passing them to the client","Avoid non-ASCII/special characters in app data directory names","On Linux, keep LANG/LC_ALL set to a UTF-8 locale so user dirs are UTF-8 encoded","Log `path.as_os_str()` (not the lossy string) when reporting path failures"],"tags":["path","encoding","utf-8","config"],"backgroundTag":"invalid-argument-value","analyzedSha":"f7dbce2997c633e484f54788035e770b3ee99773","analyzedAt":"2026-09-08T01:24:59.197Z","contentChangedAt":"2026-09-08T01:24:59.197Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}