{"record":{"id":"ba3cfbf54ae6983f","repo":"theonedev/onedev","slug":"errormessage-from-checkdeletesourcebranchconditio","errorCode":null,"errorMessage":"errorMessage (from checkDeleteSourceBranchCondition)","messagePattern":"errorMessage \\(from checkDeleteSourceBranchCondition\\)","errorType":"validation","errorClass":"NotAcceptableException","httpStatus":400,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/service/impl/DefaultPullRequestService.java","lineNumber":298,"sourceCode":"\t\tif (request.getSource().getObjectName(false) == null) {\n\t\t\tgetGitService().createBranch(request.getSourceProject(), request.getSourceBranch(),\n\t\t\t\t\trequest.getLatestUpdate().getHeadCommitHash());\n\n\t\t\tPullRequestChange change = new PullRequestChange();\n\t\t\tchange.setDate(new Date());\n\t\t\tchange.setData(new PullRequestSourceBranchRestoreData());\n\t\t\tchange.setRequest(request);\n\t\t\tchange.setUser(user);\n\t\t\tchangeService.create(change, note);\n\t\t}\n\t}\n\n\t@Transactional\n\t@Override\n\tpublic void deleteSourceBranch(User user, PullRequest request, String note) {\n        var errorMessage = request.checkDeleteSourceBranchCondition();\n        if (errorMessage != null)\n            throw new NotAcceptableException(errorMessage);\n\n\t\tif (request.getSource().getObjectName(false) != null) {\n\t\t\tprojectService.deleteBranch(request.getSourceProject(), request.getSourceBranch());\n\t\t\tPullRequestChange change = new PullRequestChange();\n\t\t\tchange.setDate(new Date());\n\t\t\tchange.setData(new PullRequestSourceBranchDeleteData());\n\t\t\tchange.setRequest(request);\n\t\t\tchange.setUser(user);\n\t\t\tchangeService.create(change, note);\n\t\t}\n\t}\n\n\t@Transactional\n\t@Override\n\tpublic void reopen(User user, PullRequest request, String note) {\n        var errorMessage = request.checkReopenCondition();\n        if (errorMessage != null)\n            throw new NotAcceptableException(errorMessage);","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/service/impl/DefaultPullRequestService.java#L280-L316","documentation":"deleteSourceBranch throws the message from PullRequest.checkDeleteSourceBranchCondition() as a NotAcceptableException when the branch is not safe to delete. The guard rejects: PR not merged, source project/branch gone, source is the default branch, merge preview missing, head not up-to-date with the merge, or other open PRs targeting the branch. The thrown message is the exact condition error.","triggerScenarios":"Calling DefaultPullRequestService.deleteSourceBranch(user, request, note) when checkDeleteSourceBranchCondition() returns non-null — e.g. \"Pull request not merged\", \"Source branch is default branch\", \"Change not updated yet\", or \"Some other pull requests are opening to this branch\".","commonSituations":"Trying to delete the source branch before the PR is merged; the source branch is the repo's default branch; the branch received new commits after the last PR update; other PRs still target that branch; automation deleting branches too early.","solutions":["Merge the pull request first, then delete the branch","Choose a non-default source branch — the default branch is never deletable this way","Wait for/re-trigger merge preview so the head commit hash is current, or update the PR","Close or retarget other open pull requests that use this branch as target","Pre-check request.checkDeleteSourceBranchCondition() == null before calling"],"exampleFix":"// before\nprService.deleteSourceBranch(user, request, \"cleanup\"); // 400 \"Pull request not merged\"\n// after\nif (request.isMerged() && request.checkDeleteSourceBranchCondition() == null)\n    prService.deleteSourceBranch(user, request, \"cleanup\");","handlingStrategy":"validation","validationCode":"String err = request.checkDeleteSourceBranchCondition();\nboolean canDelete = err == null;","typeGuard":null,"tryCatchPattern":"try {\n    prService.deleteSourceBranch(user, request, note);\n} catch (NotAcceptableException e) {\n    // e.g. not merged yet, default branch, or other open PRs depend on it\n}","preventionTips":["Delete source branches only after merge","Never attempt deletion of the default branch","Refresh/update the PR so merge preview head hash is current","Check no other open PRs target the same branch"],"tags":["pull-request","branch","delete","precondition"],"backgroundTag":"invalid-state-transition","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}