{"record":{"id":"c04190774902cd51","repo":"wasmerio/wasmer","slug":"must-be-a-valid-path-string","errorCode":null,"errorMessage":"must be a valid path string","messagePattern":"must be a valid path string","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/cli/src/commands/run/wasi.rs","lineNumber":315,"sourceCode":"        //\n        // Checking for multiple wasi versions is handled outside this function.\n        get_wasi_versions(module, false)\n    }\n\n    /// Checks if a given module has any WASI imports at all.\n    pub fn has_wasi_imports(module: &Module) -> bool {\n        // Get the wasi version in non-strict mode, so no other imports\n        // are allowed\n        get_wasi_versions(module, false).is_some()\n    }\n\n    pub(crate) fn all_volumes(&self) -> Vec<MappedDirectory> {\n        self.volumes\n            .iter()\n            .cloned()\n            .chain(self.pre_opened_directories.iter().map(|d| MappedDirectory {\n                host: d.clone(),\n                guest: d.to_str().expect(\"must be a valid path string\").to_string(),\n            }))\n            .chain(self.mapped_dirs.iter().cloned())\n            .collect_vec()\n    }\n\n    pub fn prepare(\n        &self,\n        module: &Module,\n        program_name: String,\n        args: Vec<String>,\n        rt: Arc<dyn Runtime + Send + Sync>,\n    ) -> Result<WasiEnvBuilder> {\n        let args = args.into_iter().map(|arg| arg.into_bytes());\n\n        let map_commands = self\n            .map_commands\n            .iter()\n            .map(|map| map.split_once('=').unwrap())","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/wasmerio/wasmer/blob/8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5/lib/cli/src/commands/run/wasi.rs#L297-L333","documentation":"When enumerating mapped WASI volumes, pre-opened directories (stored as PathBuf/OsString) are converted to guest path strings with .to_str().expect(...). If a pre-opened directory path contains invalid UTF-8, the conversion cannot succeed and the CLI panics with this message. Host paths on Unix may legitimately be non-UTF-8.","triggerScenarios":"Running `wasmer run` (or the WASI runner) in a directory (or with a pre-opened dir configured) whose absolute path contains non-UTF-8 bytes, causing all_volumes() to panic while building MappedDirectory list.","commonSituations":"Working inside a directory created with raw bytes in its name on Linux; legacy filesystem encodings; mounting the current directory `.` when the cwd path is non-UTF-8.","solutions":["Rename the directory/path to contain only valid UTF-8 characters","Run wasmer from a directory whose full absolute path is valid UTF-8","Avoid pre-opening the offending directory; map an ASCII-safe parent path instead","Upgrade wasmer so non-UTF-8 paths are handled with an error instead of a panic"],"exampleFix":"// before: run from a non-UTF-8 path\nwasmer run app.wasm --dir .\n// after: from an ASCII-safe path\ncd /home/user/project && wasmer run app.wasm --dir .","handlingStrategy":"validation","validationCode":"fn assert_utf8_path(p: &std::path::Path) -> Result<(), String> {\n    p.to_str().map(|_| ()).ok_or_else(|| format!(\"path {:?} is not valid UTF-8\", p))\n}\n// call for every --dir / pre-opened dir before running","typeGuard":"fn is_utf8_path(p: &std::path::Path) -> bool { p.to_str().is_some() }","tryCatchPattern":"std::panic::catch_unwind(|| wasi.all_volumes())\n    .map_err(|_| anyhow::anyhow!(\"non-UTF-8 path in WASI volumes\"))?","preventionTips":["Check `path.to_str().is_some()` for all dirs passed via --dir before running","Avoid running wasmer from directories with raw-byte or legacy-encoded names","Normalize paths to UTF-8 at configuration load time","On Linux, list directories with strict UTF-8 validation in tooling"],"tags":["wasi","path","utf-8","panic","cli"],"backgroundTag":"invalid-utf8-path","analyzedSha":"8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5","analyzedAt":"2026-09-01T23:06:31.009Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}