tauri-apps/tauri · error

Could not read binary file.

Error message

Could not read binary file.

What it means

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.

Solutions

  1. Confirm the built binary exists at the expected path (`target/<triple>/release/<name>`) before bundling; rebuild with `cargo build --release`.
  2. Check file permissions/locks (close editors, exclude from antivirus scans) and retry the bundle.
  3. Verify the `--target`/target triple passed to `tauri build` matches the compiled artifact's triple.
  4. If patching is not needed (e.g. non-AppImage formats), ensure package type configuration doesn't force patching of a missing artifact.
Defensive patterns

Strategy: validation

Validate before calling

let bin = std::path::Path::new("target/release/myapp");
if !bin.is_file() {
  panic!("binary missing at {} — run cargo build --release first", bin.display());
}
let _ = std::fs::File::open(bin).expect("binary exists but is not readable (permissions/AV lock?)");

Try / catch

match std::fs::read(binary) {
  Ok(data) => { /* patch */ }
  Err(e) => return Err(format!("Could not read binary file {}: {e}", binary.display()).into()),
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of tauri-apps/tauri@460ec35447 (2026-09-18). Data as JSON: /api/errors/5c90d9c1dac1077b. Report an issue: GitHub.

Appendix: source

Thrown at crates/tauri-bundler/src/bundle.rs:88

    crate::PackageType::MacOsBundle | crate::PackageType::Dmg => {
      // skip patching for macOS-native bundles
      return Ok(());
    }
    _ => {
      return Err(crate::Error::InvalidPackageType(
        package_type.short_name().to_owned(),
        "macOS".to_owned(),
      ));
    }
  };

  log::info!(
    "Patching {} with bundle type information: {}",
    display_path(binary),
    package_type.short_name()
  );

  let mut file_data = std::fs::read(binary).expect("Could not read binary file.");
  let bundle_var_index =
    kmp::index_of(BUNDLE_VAR_TOKEN, &file_data).ok_or(crate::Error::MissingBundleTypeVar)?;
  file_data[bundle_var_index..bundle_var_index + BUNDLE_VAR_TOKEN.len()]
    .copy_from_slice(bundle_type);

  std::fs::write(binary, &file_data).map_err(|e| crate::Error::BinaryWriteError(e.to_string()))?;

  Ok(())
}

/// Generated bundle metadata.
#[derive(Debug)]
pub struct Bundle {
  /// The package type.
  pub package_type: PackageType,
  /// All paths for this package.
  pub bundle_paths: Vec<PathBuf>,
}

View on GitHub (pinned to 460ec35447)