spacedriveapp/spacedrive · error · anyhow::Error
Downloaded file size mismatch: expected {}, got {}
Error message
Downloaded file size mismatch: expected {}, got {} What it means
After downloading, the updater compares bytes.len() against the asset 'size' reported by the GitHub API and rejects mismatches. A difference means the transfer was truncated or re-encoded (transparent gzip by a proxy/CDN), or the asset was replaced after the metadata fetch so the byte count no longer lines up.
Source
Thrown at apps/cli/src/domains/update/mod.rs:160
async fn download_file(url: &str, expected_size: u64) -> Result<Vec<u8>> {
let client = reqwest::Client::builder()
.user_agent("spacedrive-cli")
.build()?;
let response = client.get(url).send().await?;
if !response.status().is_success() {
return Err(anyhow::anyhow!(
"Failed to download: HTTP {}",
response.status()
));
}
let bytes = response.bytes().await?;
if bytes.len() as u64 != expected_size {
return Err(anyhow::anyhow!(
"Downloaded file size mismatch: expected {}, got {}",
expected_size,
bytes.len()
));
}
Ok(bytes.to_vec())
}
fn replace_binary(path: &PathBuf, data: &[u8]) -> Result<()> {
use std::fs;
// Create backup
let backup_path = path.with_extension("bak");
if path.exists() {
fs::copy(path, &backup_path)?;
}
View on GitHub (pinned to 6dfeccf211)
Solutions
- Retry 'sd update' on a stable connection
- Disable VPN/proxy for the download and retry
- Compare the release page's listed asset size with the download; if the release itself is broken, update manually from a previous release
Defensive patterns
Strategy: retry
Validate before calling
#!/usr/bin/env bash
expected=$(curl -s https://api.github.com/repos/spacedrive/spacedrive/releases/latest | jq -r '.assets[] | select(.name | contains("sd-daemon")) | .size')
actual=$(curl -sL <download_url> | wc -c)
[ "$actual" = "$expected" ] || { echo "Size mismatch ($actual != $expected)"; exit 2; } Try / catch
match download_file(&url, expected_size).await {
Ok(bytes) => bytes,
Err(e) if e.to_string().contains("size mismatch") => {
// transient truncation or re-encoding: one full re-download before giving up
download_file(&url, expected_size).await?
}
Err(e) => return Err(e),
} Prevention
- Prefer checksums (sha256 in release notes) over byte-length equality; proxies can alter length via content encoding
- Disable transparent decompression or compare post-decompress length consistently
- Retry once on mismatch before treating the release as broken
When it happens
Trigger: Connection dropped mid-body; a proxy re-compressing the binary stream; the release asset re-uploaded between metadata fetch and download.
Common situations: Flaky Wi-Fi/VPN links; corporate transparent proxies; mirrors that alter content encoding.
Related errors
- Failed to fetch releases: HTTP {}
- Failed to download: HTTP {}
- No paired devices found. Pair a device first with: sd networ
- Remote device {} is not online
- Could not find sd binary for platform: {}
AI-assisted analysis of spacedriveapp/spacedrive@6dfeccf211 (2026-08-16).
Data as JSON: /api/errors/0850ee00ef2b3db1.
Report an issue: GitHub.