{"record":{"id":"cd2125dbb9e820e0","repo":"ThreeMammals/Ocelot","slug":"completegithubrelease-statuscode","errorCode":null,"errorMessage":"CompleteGitHubRelease: StatusCode = ","messagePattern":"CompleteGitHubRelease: StatusCode = ","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"build.cake","lineNumber":1070,"sourceCode":"\r\nprivate void CompleteGitHubRelease(dynamic release)\r\n{\r\n\tint releaseId = release.id;\r\n\tstring url = release.url.ToString();\r\n\tstring body = ReleaseNotesAsJson();\r\n\tbool isPreRelease = !IsMainBranch();\r\n\tvar json = $\"{{ \\\"tag_name\\\": \\\"{versioning.NuGetVersion}\\\", \\\"target_commitish\\\": \\\"{versioning.BranchName}\\\", \\\"name\\\": \\\"{versioning.NuGetVersion}\\\", \\\"body\\\": \\\"{body}\\\", \\\"draft\\\": false, \\\"prerelease\\\": {isPreRelease.ToString().ToLower()} }}\";\r\n\tvar request = new System.Net.Http.HttpRequestMessage(new System.Net.Http.HttpMethod(\"Patch\"), url); // $\"https://api.github.com/repos/ThreeMammals/Ocelot/releases/{releaseId}\");\r\n\trequest.Content = new System.Net.Http.StringContent(json, System.Text.Encoding.UTF8, \"application/json\");\r\n\r\n\tusing (var client = new System.Net.Http.HttpClient())\r\n\t{\t\r\n\t\tSetupGitHubClient(client);\r\n\t\tvar result = client.SendAsync(request).Result;\r\n\t\tif (result.StatusCode != System.Net.HttpStatusCode.OK) \r\n\t\t{\r\n\t\t\tInformation($\"CompleteGitHubRelease: StatusCode is {result.StatusCode}. Release ID is {releaseId}. Failed to patch release with URL: {url}\");\r\n\t\t\tthrow new Exception(\"CompleteGitHubRelease: StatusCode = \" + result.StatusCode);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n/// gets the resource from the specified url\r\nprivate async Task<string> GetResourceAsync(string url)\r\n{\r\n\ttry\r\n\t{\r\n\t\tInformation(\"Getting resource from \" + url);\r\n\r\n\t\tusing var client = new System.Net.Http.HttpClient();\r\n\t\tclient.DefaultRequestHeaders.Accept.ParseAdd(\"application/vnd.github.v3+json\");\r\n\t\tclient.DefaultRequestHeaders.UserAgent.ParseAdd(\"BuildScript\");\r\n\r\n\t\tusing var response = await client.GetAsync(url);\r\n\t\tresponse.EnsureSuccessStatusCode();\r\n\t\tvar content = await response.Content.ReadAsStringAsync();\r","sourceCodeStart":1052,"sourceCodeEnd":1088,"githubUrl":"https://github.com/ThreeMammals/Ocelot/blob/d1f22d930430410bfd0233f5e9e4f92980cf7df0/build.cake#L1052-L1088","documentation":"This is a Cake build-script guard thrown by CompleteGitHubRelease when the PATCH call that finalizes an existing GitHub Release (setting tag_name, body/notes, draft/prerelease flags on the release object returned by the API) does not complete successfully. The release was already created earlier in the pipeline; completing it fails when the release id/url is stale or wrong, the GITHUB token lacks repo/release scope, the tag or commitish no longer exists, or the API rejects the JSON payload. The message is assembled by concatenating the HTTP status code returned by api.github.com so the build log shows exactly why the release could not be finalized, and throwing aborts the CI release step rather than silently leaving the release in draft/incomplete state.","triggerScenarios":"PATCH to api.github.com/repos/ThreeMammals/Ocelot/releases/{id} fails: 401/403 bad token or permissions, 404 wrong release ID, 422 invalid JSON patch payload, 409 conflict.","commonSituations":"Release was deleted between create and patch; token scope changed in CI; malformed JSON body from Newtonsoft serialization; network/proxy in CI corrupting the request.","solutions":["Read the logged StatusCode and URL; 404 means the release ID no longer exists — verify with GET /releases.","401/403: fix the GitHub token/secret scope used in SetupGitHubClient.","422: inspect the serialized JSON body for invalid fields before PATCHing.","Retry on transient 5xx once the create/upload steps are confirmed successful."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"var check = client.GetAsync($\"https://api.github.com/repos/ThreeMammals/Ocelot/releases/{releaseId}\").Result;\nif (check.StatusCode != HttpStatusCode.OK) throw new Exception($\"Release {releaseId} not found before PATCH\");","typeGuard":null,"tryCatchPattern":"try { CompleteGitHubRelease(release); }\ncatch (Exception ex) when (ex.Message.Contains(\"StatusCode = \")) { Error($\"Release completion failed: {ex.Message}\"); throw; }","preventionTips":["Confirm the release still exists before PATCHing","Validate the JSON patch body serializes correctly","Keep the token scope stable across the whole release flow","Retry transient 5xx with backoff"],"tags":["github-api","http","release","patch"],"backgroundTag":"api-error-response","analyzedSha":"d1f22d930430410bfd0233f5e9e4f92980cf7df0","analyzedAt":"2026-09-12T13:50:06.067Z","contentChangedAt":"2026-09-12T13:50:06.067Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}