Make NoSuchChangeException inherit from OrmException

More than a few throws and catch clauses already treat
NoSuchChangeException and OrmException identically; the few catch
clauses that actually care about the difference already catch
NoSuchChangeException explicitly. So this change results in a lot less
repeition.

The proximate reason for this change is I want to throw
NoSuchChangeException from ChangeNotes#load(), which is necessarily
called in a lot of places (because lazy-loading needs to be supported
when loading changes from the index with arbitrary
ListChangesOptions). Adding this new exception method is of course
possible but would have rippled out quite far.

The potential downside of this change is that authors of new code
calling a method that throws OrmException might not immediately know
that catching NoSuchChangeException is something they might want to
think about. However, I'm hoping this doesn't come up much in
practice; most callers should already have a loaded ChangeNotes or
similar object, so a NoSuchChangeException that late in the codepath
really is an unexpected error case.

Change-Id: Ibf28414344ebeeb4d37c28576feb14462e7c378a
This commit is contained in:
Dave Borowitz
2016-12-20 13:22:33 -05:00
parent e9070d639d
commit ba6b05d50c
30 changed files with 66 additions and 105 deletions

View File

@@ -29,7 +29,6 @@ import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.ApprovalsUtil;
import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.query.change.InternalChangeQuery;
import com.google.gwtorm.server.OrmException;
@@ -343,7 +342,7 @@ public class PushOneCommit {
public void assertChange(Change.Status expectedStatus,
String expectedTopic, TestAccount... expectedReviewers)
throws OrmException, NoSuchChangeException {
throws OrmException {
Change c = getChange().change();
assertThat(c.getSubject()).isEqualTo(resSubj);
assertThat(c.getStatus()).isEqualTo(expectedStatus);
@@ -352,7 +351,7 @@ public class PushOneCommit {
}
private void assertReviewers(Change c, TestAccount... expectedReviewers)
throws OrmException, NoSuchChangeException {
throws OrmException {
Iterable<Account.Id> actualIds = approvalsUtil
.getReviewers(db, notesFactory.createChecked(db, c))
.all();