{"record":{"id":"4467d5da745847cc","repo":"go-gitea/gitea","slug":"failed-to-update-pr-target-branch-resp-statuste","errorCode":null,"errorMessage":"Failed to update PR target branch: ${resp.statusText}","messagePattern":"Failed to update PR target branch: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"web_src/js/features/repo-issue.ts","lineNumber":419,"sourceCode":"\n  const editSaveButton = issueTitleEditor.querySelector('.ui.primary.button')!;\n  issueTitleEditor.addEventListener('submit', async (e) => {\n    e.preventDefault();\n    const newTitle = issueTitleInput.value.trim();\n    try {\n      if (newTitle && newTitle !== oldTitle) {\n        const resp = await POST(editSaveButton.getAttribute('data-update-url')!, {data: new URLSearchParams({title: newTitle})});\n        if (!resp.ok) {\n          throw new Error(`Failed to update issue title: ${resp.statusText}`);\n        }\n      }\n      if (prTargetUpdateUrl) {\n        const newTargetBranch = document.querySelector('#pull-target-branch')!.getAttribute('data-branch');\n        const oldTargetBranch = document.querySelector('#branch_target')!.textContent;\n        if (newTargetBranch !== oldTargetBranch) {\n          const resp = await POST(prTargetUpdateUrl, {data: new URLSearchParams({target_branch: String(newTargetBranch)})});\n          if (!resp.ok) {\n            throw new Error(`Failed to update PR target branch: ${resp.statusText}`);\n          }\n        }\n      }\n      ignoreAreYouSure(issueTitleEditor);\n      window.location.reload();\n    } catch (error) {\n      console.error(error);\n      showErrorToast(errorMessage(error));\n    }\n  });\n}\n\nexport function initRepoIssueBranchSelect() {\n  document.querySelector<HTMLElement>('#branch-select')?.addEventListener('click', (e: Event) => {\n    const el = (e.target as HTMLElement).closest('.item[data-branch]');\n    if (!el) return;\n    const pullTargetBranch = document.querySelector('#pull-target-branch')!;\n    const baseName = pullTargetBranch.getAttribute('data-basename');","sourceCodeStart":401,"sourceCodeEnd":437,"githubUrl":"https://github.com/go-gitea/gitea/blob/43ace7cc8ad5fa20027b1ca5b3ab5f1134972ed5/web_src/js/features/repo-issue.ts#L401-L437","documentation":"Thrown in the same submit handler as the title update, one step later: after a PR title saves successfully, if the edited PR target branch differs from the old one the client POSTs to the data-target-update-url (POST /{owner}/{repo}/pulls/{index}/target_branch). A non-2xx response aborts the whole save with this message; note the title change may already have been applied.","triggerScenarios":"POST to the PR target-branch endpoint returns non-ok: the new target branch does not exist in the base repo (400/404, most common), the user lacks permission to edit the PR (403), the PR is already merged/closed and locked (403/422), or a merge-conflict state the server refuses (500).","commonSituations":"Renaming/deleting the target branch in the base repo while the PR edit dialog was open, then saving; branch names that differ only in case on case-insensitive filesystems; picked a branch from the dropdown that was force-pushed away; editing a merged PR (the #pull-desc-editor usually is absent there, but race windows exist).","solutions":["Verify the chosen target branch still exists in the base repository (git ls-remote / branch dropdown) and retry","Refresh the PR page and re-apply the edit — the title may have saved already, only the branch change needs redoing","Confirm the PR is still open and the account has permission to change it","Check server logs if the branch demonstrably exists and it still fails"],"exampleFix":"// before\nconst resp = await POST(prTargetUpdateUrl, {data: new URLSearchParams({target_branch: String(newTargetBranch)})});\nif (!resp.ok) {\n  throw new Error(`Failed to update PR target branch: ${resp.statusText}`);\n}\n\n// after (report status code plus server-provided message)\nconst resp = await POST(prTargetUpdateUrl, {data: new URLSearchParams({target_branch: String(newTargetBranch)})});\nif (!resp.ok) {\n  const body = await resp.json().catch(() => null);\n  throw new Error(`Failed to update PR target branch: ${resp.status} ${body?.errorMessage ?? resp.statusText}`);\n}","handlingStrategy":"try-catch","validationCode":"// Confirm the branch exists before offering it as a target\nconst branchExists = async (baseRepoBranchesUrl: string, branch: string) => {\n  const resp = await GET(branchListUrl);\n  if (!resp.ok) return false;\n  const list = await resp.json();\n  return list.some((b: {name: string}) => b.name === branch);\n};","typeGuard":null,"tryCatchPattern":"try {\n  if (newTargetBranch !== oldTargetBranch) {\n    const resp = await POST(prTargetUpdateUrl, {data: new URLSearchParams({target_branch: String(newTargetBranch)})});\n    if (!resp.ok) throw new Error(`Failed to update PR target branch: ${resp.statusText}`);\n  }\n} catch (error) {\n  // shipped pattern: toast the error; remember the title update earlier in the handler may have succeeded,\n  // so on retry check the title before re-sending it\n  showErrorToast(errorMessage(error));\n}","preventionTips":["Treat the two POSTs (title, target branch) as independent operations that can partially succeed; verify each before retrying","Refresh the PR page if the base repo's branches may have changed (rename/delete) while editing","Ensure the account has write access and the PR is open before attempting a target-branch change"],"tags":["network","http","pull-request","git-branch","permissions","gitea-frontend"],"backgroundTag":null,"analyzedSha":"43ace7cc8ad5fa20027b1ca5b3ab5f1134972ed5","analyzedAt":"2026-08-15T09:36:00.065Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}