Submodule updates: Differentiate between conflicts and server errors

If a submodule operation cannot be performed we currently always throw a
SubmoduleException. According to its javadoc SubmoduleException messages
are user-visible.

SubmoduleException is thrown in 2 cases:
1. the submodule operation cannot be performed due to conflicts
2. the submodule operation cannot be performed due to an error in Gerrit

For 1. we should return '409 Conflict’, for 2. rather ‘500 Internal
Server Error'.  In case of 2. the exception message should not be
returned to users.

To fix this we introduce a SubmoduleConflictException as subclass of
ResourceConflictException that is thrown if there is a conflict when
performing the submodule operation and the user should get a '409
Conflict' response. In case of internal server errors we throw
StorageException now. Since StorageException is a RuntimeException this
cleans up our method signatures a bit.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: Icd60fa14a67944543ccf06df38ffee03c5d0c722
This commit is contained in:
Edwin Kempin
2020-03-09 09:13:56 +01:00
parent eb47d6c2b8
commit 2cf3dd9c75
6 changed files with 43 additions and 42 deletions

View File

@@ -163,7 +163,6 @@ import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.query.change.InternalChangeQuery;
import com.google.gerrit.server.submit.MergeOp;
import com.google.gerrit.server.submit.MergeOpRepoManager;
import com.google.gerrit.server.submit.SubmoduleException;
import com.google.gerrit.server.submit.SubmoduleOp;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdateOp;
@@ -763,8 +762,8 @@ class ReceiveCommits {
orm.setContext(TimeUtil.nowTs(), user, NotifyResolver.Result.none());
SubmoduleOp op = subOpFactory.create(branches, orm);
op.updateSuperProjects();
} catch (SubmoduleException e) {
logger.atSevere().withCause(e).log("Can't update the superprojects");
} catch (RestApiException e) {
logger.atWarning().withCause(e).log("Can't update the superprojects");
}
}
}