theonedev/onedev · error · NotAcceptableException
errorMessage (from checkRestoreSourceBranchCondition)
Error message
errorMessage (from checkRestoreSourceBranchCondition)
What it means
restoreSourceBranch throws the message returned by PullRequest.checkRestoreSourceBranchCondition() as a NotAcceptableException when the source branch cannot be restored. The condition fails when the source project no longer exists or the source branch already exists (nothing to restore). The thrown message equals whatever checkRestoreSourceBranchCondition returned.
Source
Thrown at server-core/src/main/java/io/onedev/server/service/impl/DefaultPullRequestService.java:278
query = getSession().createQuery(String.format("update CodeCommentStatusChange set %s=null where %s=:request",
CodeCommentStatusChange.PROP_COMPARE_CONTEXT + "." + CompareContext.PROP_PULL_REQUEST,
CodeCommentStatusChange.PROP_COMPARE_CONTEXT + "." + CompareContext.PROP_PULL_REQUEST));
query.setParameter("request", request);
query.executeUpdate();
dao.remove(request);
}
private GitService getGitService() {
return OneDev.getInstance(GitService.class);
}
@Transactional
@Override
public void restoreSourceBranch(User user, PullRequest request, String note) {
var errorMessage = request.checkRestoreSourceBranchCondition();
if (errorMessage != null)
throw new NotAcceptableException(errorMessage);
if (request.getSource().getObjectName(false) == null) {
getGitService().createBranch(request.getSourceProject(), request.getSourceBranch(),
request.getLatestUpdate().getHeadCommitHash());
PullRequestChange change = new PullRequestChange();
change.setDate(new Date());
change.setData(new PullRequestSourceBranchRestoreData());
change.setRequest(request);
change.setUser(user);
changeService.create(change, note);
}
}
@Transactional
@Override
public void deleteSourceBranch(User user, PullRequest request, String note) {
var errorMessage = request.checkDeleteSourceBranchCondition();View on GitHub (pinned to d44925c47c)
Solutions
- If the branch already exists, no restore is needed — skip the call
- If the source project was deleted, restore/recreate the project first (or abandon the restore)
- Call request.checkRestoreSourceBranchCondition() yourself and only restore when it returns null
Example fix
// before
prService.restoreSourceBranch(user, request, "restore"); // 400 "Source branch already exists"
// after
if (request.checkRestoreSourceBranchCondition() == null)
prService.restoreSourceBranch(user, request, "restore"); Defensive patterns
Strategy: validation
Validate before calling
String err = request.checkRestoreSourceBranchCondition(); boolean canRestore = err == null;
Try / catch
try {
prService.restoreSourceBranch(user, request, note);
} catch (NotAcceptableException e) {
// branch already exists or source project gone
} Prevention
- Only offer 'restore branch' when the branch is absent
- Check source project existence first
- Treat an existing branch as already-restored
When it happens
Trigger: Calling DefaultPullRequestService.restoreSourceBranch(user, request, note) when checkRestoreSourceBranchCondition() returns non-null: getSourceProject() == null ("Source project no longer exists") or getSource().getObjectName(false) != null ("Source branch already exists").
Common situations: Clicking 'restore source branch' on a PR whose branch was recreated manually; source fork/repository was deleted so restoration target is gone; scripting branch restores without checking current branch state.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- errorMessage (from checkDeleteSourceBranchCondition)
- No code in target project:
- Cannot delete this branch as it has workspaces
- Cannot delete pull request "${request.getReference().toStrin
- errorMessage (from checkReopenCondition)
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/82a2978450c03697.
Report an issue: GitHub.