{"record":{"id":"1348df898d5f6b11","repo":"tauri-apps/tauri","slug":"failed-to-write-global-api-script","errorCode":null,"errorMessage":"failed to write global API script","messagePattern":"failed to write global API script","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri-utils/src/plugin.rs","lineNumber":59,"sourceCode":"      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\n        .into_iter()\n        .map(|p| {","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/tauri-apps/tauri/blob/460ec35447493200d64290dd7f015d5a91d0fd58/crates/tauri-utils/src/plugin.rs#L41-L77","documentation":"In the same function, `fs::write(out_dir.join(GLOBAL_API_SCRIPT_FILE_LIST_PATH), ...)` is wrapped in `expect(\"failed to write global API script\")`. It panics when the file list cannot be written — typically a bad `out_dir`, missing parent directory, or permission problem.","triggerScenarios":"Calling `save_global_api_scripts_paths` with an `out_dir` that does not exist, is read-only, or where `GLOBAL_API_SCRIPT_FILE_LIST_PATH` cannot be created (permissions, disk full, path is a directory).","commonSituations":"Passing a wrong/hardcoded out dir instead of Cargo's `OUT_DIR`; sandboxed CI runners with read-only build dirs; antivirus or ACLs blocking writes on Windows.","solutions":["Verify `out_dir` is Cargo's real `OUT_DIR` (from `env::var(\"OUT_DIR\")`) and exists before writing","Create the directory (`fs::create_dir_all(out_dir)`) if it is missing","Check write permissions on the build output directory / CI workspace","Ensure the target path is not itself a directory"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"let out_dir = PathBuf::from(env::var_os(\"OUT_DIR\").expect(\"OUT_DIR not set\"));\nassert!(out_dir.is_dir(), \"OUT_DIR missing: {}\", out_dir.display());","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use Cargo's provided OUT_DIR, never a hardcoded path","Ensure CI workspaces/target dirs are writable","Call `fs::create_dir_all` for custom output locations"],"tags":["file-write","filesystem","panic","build-script","tauri"],"backgroundTag":"file-write-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"}