{"record":{"id":"4e2bb5ca92ed748d","repo":"tauri-apps/tauri","slug":"failed-to-serialize-global-api-script-paths","errorCode":null,"errorMessage":"failed to serialize global API script paths","messagePattern":"failed to serialize global API script paths","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri-utils/src/plugin.rs","lineNumber":57,"sourceCode":"\n    for (key, value) in vars_os() {\n      let key = key.to_string_lossy();\n\n      if key == format!(\"DEP_TAURI_{GLOBAL_API_SCRIPT_PATH_KEY}\") {\n        tauri_global_scripts = Some(PathBuf::from(value));\n      } else if key.starts_with(\"DEP_\") && key.ends_with(GLOBAL_API_SCRIPT_PATH_KEY) {\n        let script_path = PathBuf::from(value);\n        scripts.push(script_path);\n      }\n    }\n\n    if let Some(tauri_global_scripts) = tauri_global_scripts {\n      scripts.insert(0, tauri_global_scripts);\n    }\n\n    fs::write(\n      out_dir.join(GLOBAL_API_SCRIPT_FILE_LIST_PATH),\n      serde_json::to_string(&scripts).expect(\"failed to serialize global API script paths\"),\n    )\n    .expect(\"failed to write global API script\");\n  }\n\n  /// Read global api scripts from [`GLOBAL_API_SCRIPT_FILE_LIST_PATH`]\n  pub fn read_global_api_scripts(out_dir: &Path) -> Option<Vec<String>> {\n    let global_scripts_path = out_dir.join(GLOBAL_API_SCRIPT_FILE_LIST_PATH);\n    if !global_scripts_path.exists() {\n      return None;\n    }\n\n    let global_scripts_str = fs::read_to_string(global_scripts_path)\n      .expect(\"failed to read plugin global API script paths\");\n    let global_scripts = serde_json::from_str::<Vec<PathBuf>>(&global_scripts_str)\n      .expect(\"failed to parse plugin global API script paths\");\n\n    Some(\n      global_scripts","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/tauri-apps/tauri/blob/460ec35447493200d64290dd7f015d5a91d0fd58/crates/tauri-utils/src/plugin.rs#L39-L75","documentation":"`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.","triggerScenarios":"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`.","commonSituations":"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.","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"],"exampleFix":"// before\nfs::write(out_dir.join(GLOBAL_API_SCRIPT_FILE_LIST_PATH), serde_json::to_string(&scripts).expect(\"failed to serialize global API script paths\"))\n// after\nlet json = serde_json::to_string(&scripts).unwrap_or_else(|e| panic!(\"invalid path data: {e}\"));\nfs::write(out_dir.join(GLOBAL_API_SCRIPT_FILE_LIST_PATH), json)","handlingStrategy":"validation","validationCode":"for p in &scripts {\n  assert!(p.to_str().is_some(), \"non-UTF8 path in global scripts: {:?}\", p);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep all script paths valid UTF-8","Clean-rebuild when target/ contents look stale or corrupted","Avoid constructing paths from raw OsStr bytes"],"tags":["serialization","json","panic","build-script","tauri"],"backgroundTag":"json-serialization-failed","analyzedSha":"460ec35447493200d64290dd7f015d5a91d0fd58","analyzedAt":"2026-09-18T23:55:51.277Z","contentChangedAt":"2026-09-18T23:55:51.277Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}