{"record":{"id":"19c71f9150d58554","repo":"CoplayDev/unity-mcp","slug":"file-download-failed-int-response-statuscode","errorCode":null,"errorMessage":"File download failed: {(int)response.StatusCode} {response.ReasonPhrase} ({url})\\n{body}","messagePattern":"File download failed: (.+?) (.+?) \\((.+?)\\)\\\\n(.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"MCPForUnity/Editor/Setup/SkillSyncService.cs","lineNumber":309,"sourceCode":"        internal static string DownloadString(HttpClient client, string url)\n        {\n            using var response = client.GetAsync(url).GetAwaiter().GetResult();\n            var body = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();\n            if (!response.IsSuccessStatusCode)\n            {\n                throw new InvalidOperationException($\"GitHub request failed: {(int)response.StatusCode} {response.ReasonPhrase} ({url})\\n{body}\");\n            }\n\n            return body;\n        }\n\n        private static byte[] DownloadBytes(HttpClient client, string url)\n        {\n            using var response = client.GetAsync(url).GetAwaiter().GetResult();\n            if (!response.IsSuccessStatusCode)\n            {\n                var body = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();\n                throw new InvalidOperationException($\"File download failed: {(int)response.StatusCode} {response.ReasonPhrase} ({url})\\n{body}\");\n            }\n\n            return response.Content.ReadAsByteArrayAsync().GetAwaiter().GetResult();\n        }\n\n        internal static string NormalizeRemotePath(string path)\n        {\n            if (string.IsNullOrWhiteSpace(path))\n            {\n                return string.Empty;\n            }\n\n            return path.Replace('\\\\', '/').Trim().Trim('/');\n        }\n\n        private static string CombineRemotePath(string left, string right)\n        {\n            var normalizedLeft = NormalizeRemotePath(left);","sourceCodeStart":291,"sourceCodeEnd":327,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/MCPForUnity/Editor/Setup/SkillSyncService.cs#L291-L327","documentation":"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.","triggerScenarios":"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.","commonSituations":"Branch advanced during a sync; special characters in the file path were not encoded as GitHub expects; intermittent raw.githubusercontent.com outage.","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."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    var bytes = DownloadBytes(client, url);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"File download failed\"))\n{\n    log?.Invoke($\"Transient raw-file download failure for {url}. Retrying sync may help.\");\n    throw;\n}","preventionTips":["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."],"tags":["github","download","http"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}