theonedev/onedev · error · EntityNotFoundException

Unable to find pull request #<n> in project <project>

Error message

Unable to find pull request #<n> in project <project>

What it means

InvalidPullRequestPage loads the pull request by number and throws EntityNotFoundException when PullRequestService.find returns null, i.e. no such request number exists in the project. This page exists specifically to report invalid/deleted pull requests, so the error means the referenced PR is entirely absent.

Source

Thrown at server-core/src/main/java/io/onedev/server/web/page/project/pullrequests/InvalidPullRequestPage.java:58

import io.onedev.server.web.util.ConfirmClickModifier;

public class InvalidPullRequestPage extends ProjectPage {

	public static final String PARAM_REQUEST = "request";
	
	private IModel<PullRequest> requestModel;
	
	public InvalidPullRequestPage(PageParameters params) {
		super(params);
		
		requestModel = new LoadableDetachableModel<PullRequest>() {

			@Override
			protected PullRequest load() {
				Long requestNumber = params.get(PARAM_REQUEST).toLong();
				PullRequest request = OneDev.getInstance(PullRequestService.class).find(getProject(), requestNumber);
				if (request == null)
					throw new EntityNotFoundException("Unable to find pull request #" + requestNumber + " in project " + getProject());
				Preconditions.checkState(!request.isValid());
				return request;
			}

		};
	}

	@Override
	protected void onInitialize() {
		super.onInitialize();
		
		var request = getPullRequest();
		add(new Label("missingCommits", StringUtils.join(request.getMissingCommits().stream().map(ObjectId::getName).collect(toList()), " ")));
		add(new Label("requestBranches", escapeHtml5(request.getTargetBranch()) + " &larr; " + escapeHtml5(request.getSourceBranch())).setEscapeModelStrings(false));
		if (request.getDescription() != null) {
			add(new Label("requestTitle", request.getTitle()).add(AttributeAppender.append("class", "mb-4")));
			add(new MarkdownViewer("requestDescription", Model.of(request.getDescription()), null));
		} else {

View on GitHub (pinned to d44925c47c)

Solutions

  1. Verify the PR number exists in this project's pull request list.
  2. Check that the URL points at the correct project (fork vs target project).
  3. Open the PR from the pull request list instead of a stale link.

Example fix

// before
open("/~/pull_requests/" + number + "/invalid");
// after
PullRequest pr = pullRequestService.find(project, number);
if (pr == null) throw new IllegalArgumentException("PR #" + number + " not found in " + project.getPath());
Defensive patterns

Strategy: validation

Validate before calling

PullRequest request = pullRequestService.find(project, requestNumber);
if (request == null) throw new IllegalArgumentException("PR #" + requestNumber + " not found in " + project.getPath());

Type guard

boolean pullRequestExists(Project p, long number) { return OneDev.getInstance(PullRequestService.class).find(p, number) != null; }

Try / catch

try { loadPullRequest(number); } catch (EntityNotFoundException e) { redirectToList(project); }

Prevention

When it happens

Trigger: Loading an invalid-PR URL whose PARAM_REQUEST number does not match any pull request in the current project; requesting a PR number that was never created or was removed.

Common situations: Deleted pull request still referenced by an old link or notification; PR created in a fork but looked up in the target project; typo in the PR number in a manually constructed URL.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06). Data as JSON: /api/errors/bc625016afc1a7b8. Report an issue: GitHub.