{"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/460ec35447493200d64290dd7f015d5a91d0fd58/crates/tauri-bundler/src/bundle.rs#L70-L106","documentation":"In tauri-bundler's patch_binary, the bundled executable is read entirely into memory with `std::fs::read` and the result is unwrapped with this message. The panic means the binary file produced by `cargo build` could not be read (missing file, permissions, or I/O error) at the moment the bundler tried to inject bundle-type information. Because it uses expect, the underlying io::Error is not reported.","triggerScenarios":"tauri_bundler::bundle::bundle_project invoking patch_binary with a path to an executable that does not exist or is unreadable — e.g. the cargo build produced no binary at the expected path, or the file was removed/moved between build and bundling.","commonSituations":"Building with a target triple whose binary wasn't produced (`--target` mismatch); antivirus or file locks on Windows briefly holding the exe; read-permission loss after a copy step; running the bundler against a custom binary_path that no longer exists.","solutions":["Confirm the built binary exists at the expected path (`target/<triple>/release/<name>`) before bundling; rebuild with `cargo build --release`.","Check file permissions/locks (close editors, exclude from antivirus scans) and retry the bundle.","Verify the `--target`/target triple passed to `tauri build` matches the compiled artifact's triple.","If patching is not needed (e.g. non-AppImage formats), ensure package type configuration doesn't force patching of a missing artifact."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"let bin = std::path::Path::new(\"target/release/myapp\");\nif !bin.is_file() {\n  panic!(\"binary missing at {} — run cargo build --release first\", bin.display());\n}\nlet _ = std::fs::File::open(bin).expect(\"binary exists but is not readable (permissions/AV lock?)\");","typeGuard":null,"tryCatchPattern":"match std::fs::read(binary) {\n  Ok(data) => { /* patch */ }\n  Err(e) => return Err(format!(\"Could not read binary file {}: {e}\", binary.display()).into()),\n}","preventionTips":["Build with the exact target triple you intend to bundle for.","Exclude target/ from antivirus real-time scanning on Windows.","Re-run the bundler once after transient locks; make bundling a separate step from building."],"tags":["filesystem","read","bundling","binary"],"backgroundTag":"file-read-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"}