CoplayDev/unity-mcp · error · InvalidOperationException
File download failed: {(int)response.StatusCode} {response.R
Error message
File download failed: {(int)response.StatusCode} {response.ReasonPhrase} ({url})\n{body} What it means
DownloadBytes throws when fetching a raw file from raw.githubusercontent.com returns a non-success status. This happens during ApplyPlan, after the tree listed the file, so a failure here usually indicates the file became unreachable between the tree fetch and the download.
Source
Thrown at MCPForUnity/Editor/Setup/SkillSyncService.cs:309
internal static string DownloadString(HttpClient client, string url)
{
using var response = client.GetAsync(url).GetAwaiter().GetResult();
var body = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
if (!response.IsSuccessStatusCode)
{
throw new InvalidOperationException($"GitHub request failed: {(int)response.StatusCode} {response.ReasonPhrase} ({url})\n{body}");
}
return body;
}
private static byte[] DownloadBytes(HttpClient client, string url)
{
using var response = client.GetAsync(url).GetAwaiter().GetResult();
if (!response.IsSuccessStatusCode)
{
var body = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
throw new InvalidOperationException($"File download failed: {(int)response.StatusCode} {response.ReasonPhrase} ({url})\n{body}");
}
return response.Content.ReadAsByteArrayAsync().GetAwaiter().GetResult();
}
internal static string NormalizeRemotePath(string path)
{
if (string.IsNullOrWhiteSpace(path))
{
return string.Empty;
}
return path.Replace('\\', '/').Trim().Trim('/');
}
private static string CombineRemotePath(string left, string right)
{
var normalizedLeft = NormalizeRemotePath(left);View on GitHub (pinned to c21bf496bc)
Solutions
- Retry the sync (transient races and CDN blips often clear).
- Confirm the file still exists at the synced commit SHA.
- Check the URL in the message for path-encoding issues.
- Avoid syncing while the target branch is being force-pushed.
Defensive patterns
Strategy: retry
Try / catch
try
{
var bytes = DownloadBytes(client, url);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("File download failed"))
{
log?.Invoke($"Transient raw-file download failure for {url}. Retrying sync may help.");
throw;
} Prevention
- Avoid syncing while the target branch is being force-pushed.
- Retry once on transient raw.githubusercontent.com failures.
- Check the URL for path-encoding issues when failures persist.
When it happens
Trigger: 404 because the file was deleted/renamed between the tree fetch and download (branch moved); path encoding mismatch in the constructed raw URL; transient network error or CDN issue.
Common situations: Branch advanced during a sync; special characters in the file path were not encoded as GitHub expects; intermittent raw.githubusercontent.com outage.
Related errors
- GitHub request failed: {(int)response.StatusCode} {response.
- fal {phase} failed (status={res?.Status}): {detail}
- fal {phase} failed (status={res?.Status}): {detail}
- {context}: refusing to send credentials to an unexpected hos
- Repo URL is not a recognized GitHub repository URL: {repoUrl
AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13).
Data as JSON: /api/errors/19c71f9150d58554.
Report an issue: GitHub.