Search in sources :

Example 31 with NoSuchChangeException

use of com.google.gerrit.server.project.NoSuchChangeException in project gerrit by GerritCodeReview.

the class GetContent method getMergeList.

private byte[] getMergeList(ChangeNotes notes) throws IOException {
    Change.Id changeId = notes.getChangeId();
    PatchSet ps = psUtil.current(notes);
    if (ps == null) {
        throw new NoSuchChangeException(changeId);
    }
    try (Repository git = gitManager.openRepository(notes.getProjectName());
        RevWalk revWalk = new RevWalk(git)) {
        return Text.forMergeList(ComparisonType.againstAutoMerge(), revWalk.getObjectReader(), ps.commitId()).getContent();
    } catch (RepositoryNotFoundException e) {
        throw new NoSuchChangeException(changeId, e);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) RevWalk(org.eclipse.jgit.revwalk.RevWalk)

Example 32 with NoSuchChangeException

use of com.google.gerrit.server.project.NoSuchChangeException in project gerrit by GerritCodeReview.

the class BatchUpdate method wrapAndThrowException.

private static void wrapAndThrowException(Exception e) throws UpdateException, RestApiException {
    // exception types.
    if (e instanceof InvalidChangeOperationException || e instanceof LimitExceededException) {
        throw new ResourceConflictException(e.getMessage(), e);
    } else if (e instanceof NoSuchChangeException || e instanceof NoSuchRefException || e instanceof NoSuchProjectException) {
        throw new ResourceNotFoundException(e.getMessage(), e);
    } else if (e instanceof CommentsRejectedException) {
        // status code and it's isolated in monitoring.
        throw new BadRequestException(e.getMessage(), e);
    }
    Throwables.throwIfUnchecked(e);
    // Propagate REST API exceptions thrown by operations; they commonly throw exceptions like
    // ResourceConflictException to indicate an atomic update failure.
    Throwables.throwIfInstanceOf(e, UpdateException.class);
    Throwables.throwIfInstanceOf(e, RestApiException.class);
    // Otherwise, wrap in a generic UpdateException, which does not include a user-visible message.
    throw new UpdateException(e);
}
Also used : InvalidChangeOperationException(com.google.gerrit.server.project.InvalidChangeOperationException) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) NoSuchRefException(com.google.gerrit.server.project.NoSuchRefException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) LimitExceededException(com.google.gerrit.server.notedb.LimitExceededException) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Aggregations

NoSuchChangeException (com.google.gerrit.server.project.NoSuchChangeException)32 Change (com.google.gerrit.reviewdb.client.Change)13 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)10 IOException (java.io.IOException)9 Change (com.google.gerrit.entities.Change)7 PatchSet (com.google.gerrit.entities.PatchSet)7 OrmException (com.google.gwtorm.server.OrmException)7 Repository (org.eclipse.jgit.lib.Repository)7 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)6 ObjectId (org.eclipse.jgit.lib.ObjectId)5 RevWalk (org.eclipse.jgit.revwalk.RevWalk)5 StorageException (com.google.gerrit.exceptions.StorageException)4 AuthException (com.google.gerrit.extensions.restapi.AuthException)4 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)4 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)4 LargeObjectException (com.google.gerrit.server.git.LargeObjectException)4 InvalidChangeOperationException (com.google.gerrit.server.project.InvalidChangeOperationException)4 PatchScript (com.google.gerrit.common.data.PatchScript)3 DiffPreferencesInfo (com.google.gerrit.extensions.client.DiffPreferencesInfo)3 DiffInfo (com.google.gerrit.extensions.common.DiffInfo)3