{"record":{"id":"21fe3d5aeab63702","repo":"tauri-apps/tauri","slug":"failed-to-open-file","errorCode":null,"errorMessage":"Failed to open file","messagePattern":"Failed to open file","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri-bundler/src/utils/http_utils.rs","lineNumber":180,"sourceCode":"  for i in 0..zipa.len() {\n    let mut file = zipa.by_index(i)?;\n\n    if let Some(name) = file.enclosed_name() {\n      let dest_path = path.join(name);\n      if file.is_dir() {\n        create_dir_all(&dest_path)?;\n        continue;\n      }\n\n      let parent = dest_path.parent().expect(\"Failed to get parent\");\n\n      if !parent.exists() {\n        create_dir_all(parent)?;\n      }\n\n      let mut buff: Vec<u8> = Vec::new();\n      file.read_to_end(&mut buff)?;\n      let mut fileout = File::create(dest_path).expect(\"Failed to open file\");\n\n      fileout.write_all(&buff)?;\n    }\n  }\n\n  Ok(())\n}\n\n#[cfg(test)]\nmod tests {\n  use super::generate_github_mirror_url_from_template;\n  use std::env;\n\n  const GITHUB_ASSET_URL: &str =\n    \"https://github.com/wixtoolset/wix3/releases/download/wix3112rtm/wix311-binaries.zip\";\n  const NON_GITHUB_ASSET_URL: &str = \"https://someotherwebsite.com/somefile.zip\";\n\n  #[test]","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/tauri-apps/tauri/blob/460ec35447493200d64290dd7f015d5a91d0fd58/crates/tauri-bundler/src/utils/http_utils.rs#L162-L198","documentation":"In extract_zip, after reading a zip entry into a buffer, tauri-bundler creates the destination file with File::create(dest_path).expect(\"Failed to open file\"). Any OS-level failure to create/overwrite that file (permissions, path length, read-only, name collision with a directory) becomes this panic instead of a graceful error.","triggerScenarios":"get_and_extract_wix -> extract_zip when File::create on a zip entry's destination fails: destination is inside a read-only directory, an antivirus locks the file, the path exceeds MAX_PATH on Windows, or a directory already exists with the same name.","commonSituations":"Windows Defender/AV scanning quarantines files during WiX extraction; previously extracted WiX cache contains read-only files or a directory where a file should be; long paths under deep %LOCALAPPDATA% cache; running without write permission to the cache dir.","solutions":["Delete the existing WiX tools cache (e.g. %LOCALAPPDATA%/tauri/WixTools3139) and re-run the build so files are recreated fresh.","Add an antivirus exclusion for the tauri cache directory or temporarily disable real-time scanning during the build.","Run the build from an elevated shell or fix ACLs on the cache directory so it is writable.","Enable Windows long-path support (LongPathsEnabled) or move the cache to a shorter path."],"exampleFix":"// before (run in project shell)\ntauri build\n// after (clear the bad cache first, PowerShell)\nRemove-Item -Recurse -Force \"$env:LOCALAPPDATA\\tauri\\WixTools*\"\ntauri build","handlingStrategy":"try-catch","validationCode":"// Check the WiX cache directory is writable before extraction\nuse std::path::Path;\nlet probe = cache_dir.join(\".write_probe\");\nstd::fs::write(&probe, b\"x\").expect(\"WiX cache dir not writable (AV lock or permissions?)\");\nlet _ = std::fs::remove_file(&probe);","typeGuard":null,"tryCatchPattern":"// Catch OS-level write failures during WiX setup\nif let Err(e) = ensure_wix(&cache_dir) {\n  eprintln!(\"WiX extraction failed: {e}; clearing cache and retrying\");\n  let _ = std::fs::remove_dir_all(&cache_dir);\n  ensure_wix(&cache_dir)?;\n}","preventionTips":["Add an antivirus exclusion for the tauri cache directory.","Enable Windows long paths and keep the cache path short.","Run builds with write access to %LOCALAPPDATA% and clean stale read-only caches."],"tags":["filesystem","windows","file-write","zip","wix"],"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"}