tauri-apps/tauri · error
failed to serialize global API script paths
Error message
failed to serialize global API script paths
What it means
`save_global_api_scripts_paths` serializes the collected global API script paths to JSON with `serde_json::to_string(...).expect(...)`. Serialization of a `Vec<PathBuf>` can only fail if a path contains invalid UTF-16/unrepresentable characters (e.g. interior NULs on Unix), so this panic signals a corrupted or non-representable path value.
Solutions
- Sanitize/validate all collected script paths are valid UTF-8 before saving
- Rebuild cleanly (`cargo clean`) to flush corrupted generated values
- Find the source producing non-UTF8 path components (env vars, config) and fix it
Example fix
// before
fs::write(out_dir.join(GLOBAL_API_SCRIPT_FILE_LIST_PATH), serde_json::to_string(&scripts).expect("failed to serialize global API script paths"))
// after
let json = serde_json::to_string(&scripts).unwrap_or_else(|e| panic!("invalid path data: {e}"));
fs::write(out_dir.join(GLOBAL_API_SCRIPT_FILE_LIST_PATH), json) Defensive patterns
Strategy: validation
Validate before calling
for p in &scripts {
assert!(p.to_str().is_some(), "non-UTF8 path in global scripts: {:?}", p);
} Prevention
- Keep all script paths valid UTF-8
- Clean-rebuild when target/ contents look stale or corrupted
- Avoid constructing paths from raw OsStr bytes
When it happens
Trigger: Calling `tauri_utils::plugin::save_global_api_scripts_paths` where one of the collected `PathBuf`s contains invalid Unicode (e.g. interior NUL byte), making `serde_json::to_string` return `Err`.
Common situations: Paths constructed from raw bytes read from the filesystem on Unix (OsStr with non-UTF8 bytes); corrupted environment or generated path values; extremely rare in normal builds.
Understand the failure class
Background: "JSON serialization failed", "not JSON serializable", "Failed to serialize": why JSON marshaling errors happen and how to fix them — this error's family across 46 libraries.
Related errors
- failed to parse plugin global API script paths
- failed to canonicalize global API script path
- failed to parse capabilities
- failed to parse plugin manifest map
- failed to read Android codegen directory
AI-assisted analysis of tauri-apps/tauri@460ec35447 (2026-09-18).
Data as JSON: /api/errors/4e2bb5ca92ed748d.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tauri-utils/src/plugin.rs:57
for (key, value) in vars_os() {
let key = key.to_string_lossy();
if key == format!("DEP_TAURI_{GLOBAL_API_SCRIPT_PATH_KEY}") {
tauri_global_scripts = Some(PathBuf::from(value));
} else if key.starts_with("DEP_") && key.ends_with(GLOBAL_API_SCRIPT_PATH_KEY) {
let script_path = PathBuf::from(value);
scripts.push(script_path);
}
}
if let Some(tauri_global_scripts) = tauri_global_scripts {
scripts.insert(0, tauri_global_scripts);
}
fs::write(
out_dir.join(GLOBAL_API_SCRIPT_FILE_LIST_PATH),
serde_json::to_string(&scripts).expect("failed to serialize global API script paths"),
)
.expect("failed to write global API script");
}
/// Read global api scripts from [`GLOBAL_API_SCRIPT_FILE_LIST_PATH`]
pub fn read_global_api_scripts(out_dir: &Path) -> Option<Vec<String>> {
let global_scripts_path = out_dir.join(GLOBAL_API_SCRIPT_FILE_LIST_PATH);
if !global_scripts_path.exists() {
return None;
}
let global_scripts_str = fs::read_to_string(global_scripts_path)
.expect("failed to read plugin global API script paths");
let global_scripts = serde_json::from_str::<Vec<PathBuf>>(&global_scripts_str)
.expect("failed to parse plugin global API script paths");
Some(
global_scriptsView on GitHub (pinned to 460ec35447)