{"record":{"id":"5c90d9c1dac1077b","repo":"tauri-apps/tauri","slug":"could-not-read-binary-file","errorCode":null,"errorMessage":"Could not read binary file.","messagePattern":"Could not read binary file\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri-bundler/src/bundle.rs","lineNumber":88,"sourceCode":"    crate::PackageType::MacOsBundle | crate::PackageType::Dmg => {\n      // skip patching for macOS-native bundles\n      return Ok(());\n    }\n    _ => {\n      return Err(crate::Error::InvalidPackageType(\n        package_type.short_name().to_owned(),\n        \"macOS\".to_owned(),\n      ))\n    }\n  };\n\n  log::info!(\n    \"Patching {} with bundle type information: {}\",\n    display_path(binary),\n    package_type.short_name()\n  );\n\n  let mut file_data = std::fs::read(binary).expect(\"Could not read binary file.\");\n  let bundle_var_index =\n    kmp::index_of(BUNDLE_VAR_TOKEN, &file_data).ok_or(crate::Error::MissingBundleTypeVar)?;\n  file_data[bundle_var_index..bundle_var_index + BUNDLE_VAR_TOKEN.len()]\n    .copy_from_slice(bundle_type);\n\n  std::fs::write(binary, &file_data).map_err(|e| crate::Error::BinaryWriteError(e.to_string()))?;\n\n  Ok(())\n}\n\n/// Generated bundle metadata.\n#[derive(Debug)]\npub struct Bundle {\n  /// The package type.\n  pub package_type: PackageType,\n  /// All paths for this package.\n  pub bundle_paths: Vec<PathBuf>,\n}","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/tauri-apps/tauri/blob/52e4b6e71d8632a7e648f866c442e287ecddee34/crates/tauri-bundler/src/bundle.rs#L70-L106","documentation":"In tauri-bundler's patch_binary, after bundling the app the bundler re-reads the compiled application binary to overwrite the __TAURI_BUNDLE_TYPE_VAR__ token with the package type (deb/rpm/appimage/msi/nsis). This expect fires when std::fs::read on the binary path returns an Err — the file is missing, moved, locked, or unreadable at patch time.","triggerScenarios":"Running tauri build/bundle when the app binary path recorded for patching no longer exists (target dir cleaned or artifacts moved mid-run), when another process (antivirus, indexer) holds an exclusive lock on Windows, or when permissions deny read access to target/<profile>/<app>.","commonSituations":"Build hooks (beforeBuildCommand/afterBuildCommand) or scripts that move/delete artifacts between the cargo build and bundling phases; antivirus quarantining unsigned exes on Windows; binary name mismatch between tauri.conf.json (productName/binary) and the --target/features actually built; permission-restricted CI runners.","solutions":["Rebuild from scratch with tauri build (or cargo tauri build) so the binary exists immediately before patching","Check the exact path in the preceding log line 'Patching <path> with bundle type information' and verify it exists and is readable","Confirm the binary name matches productName/binary in tauri.conf.json and the --target triple passed to the CLI","On Windows, exclude the target directory from antivirus/Defender real-time scanning"],"exampleFix":"# before — bundling against a target dir whose artifacts were removed\ncargo clean && tauri bundle\n\n# after — let tauri build produce the binary right before bundling\ntauri build --bundles deb","handlingStrategy":"validation","validationCode":"// Rust — before invoking bundling programmatically\nlet binary = std::path::Path::new(\"target/release/my-app\");\nif !binary.is_file() {\n  anyhow::bail!(\"app binary missing at {} — run cargo build first\", binary.display());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always enter bundling through tauri build / tauri bundle so cargo build precedes patch_binary","Keep beforeBuildCommand/afterBuildCommand hooks from moving or deleting files under target/","On Windows, add the target directory to antivirus exclusions"],"tags":["tauri-bundler","filesystem","binary","io","panic"],"backgroundTag":"file-read-failure","analyzedSha":"52e4b6e71d8632a7e648f866c442e287ecddee34","analyzedAt":"2026-08-20T13:59:20.734Z","contentChangedAt":"2026-08-20T13:59:20.734Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}