Search in sources :

Example 96 with StorageException

use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.

the class ReviewCommand method addPatchSetId.

@Argument(index = 0, required = true, multiValued = true, metaVar = "{COMMIT | CHANGE,PATCHSET}", usage = "list of commits or patch sets to review")
void addPatchSetId(String token) {
    try {
        PatchSet ps = psParser.parsePatchSet(token, projectState, branch);
        patchSets.add(ps);
    } catch (UnloggedFailure e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    } catch (StorageException e) {
        throw new IllegalArgumentException("database error", e);
    }
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) StorageException(com.google.gerrit.exceptions.StorageException) Argument(org.kohsuke.args4j.Argument)

Example 97 with StorageException

use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.

the class LsUserRefs method run.

@Override
protected void run() throws Failure {
    enableGracefulStop();
    Account.Id userAccountId;
    try {
        userAccountId = accountResolver.resolve(userName).asUnique().account().id();
    } catch (UnprocessableEntityException e) {
        stdout.println(e.getMessage());
        stdout.flush();
        return;
    } catch (StorageException | IOException | ConfigInvalidException e) {
        throw die(e);
    }
    Project.NameKey projectName = projectState.getNameKey();
    try (Repository repo = repoManager.openRepository(projectName);
        ManualRequestContext ctx = requestContext.openAs(userAccountId)) {
        try {
            Collection<Ref> refsMap = permissionBackend.user(ctx.getUser()).project(projectName).filter(repo.getRefDatabase().getRefs(), repo, RefFilterOptions.defaults());
            for (Ref ref : refsMap) {
                if (!onlyRefsHeads || ref.getName().startsWith(RefNames.REFS_HEADS)) {
                    stdout.println(ref);
                }
            }
        } catch (IOException | PermissionBackendException e) {
            throw new Failure(1, "fatal: Error reading refs: '" + projectName, e);
        }
    } catch (RepositoryNotFoundException e) {
        throw die("'" + projectName + "': not a git archive", e);
    } catch (IOException e) {
        throw die("Error opening: '" + projectName, e);
    }
}
Also used : Account(com.google.gerrit.entities.Account) UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) IOException(java.io.IOException) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) Project(com.google.gerrit.entities.Project) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) ManualRequestContext(com.google.gerrit.server.util.ManualRequestContext) StorageException(com.google.gerrit.exceptions.StorageException)

Example 98 with StorageException

use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.

the class Index method get.

/**
 * Get a single document from the index.
 *
 * @param key document key.
 * @param opts query options. Options that do not make sense in the context of a single document,
 *     such as start, will be ignored.
 * @return a single document if present.
 */
default Optional<V> get(K key, QueryOptions opts) {
    opts = opts.withStart(0).withLimit(2);
    ImmutableList<V> results;
    try {
        results = getSource(keyPredicate(key), opts).read().toList();
    } catch (QueryParseException e) {
        throw new StorageException("Unexpected QueryParseException during get()", e);
    }
    if (results.size() > 1) {
        throw new StorageException("Multiple results found in index for key " + key + ": " + results);
    }
    return results.stream().findFirst();
}
Also used : StorageException(com.google.gerrit.exceptions.StorageException) QueryParseException(com.google.gerrit.index.query.QueryParseException)

Example 99 with StorageException

use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.

the class Index method getRaw.

/**
 * Get a single raw document from the index.
 *
 * @param key document key.
 * @param opts query options. Options that do not make sense in the context of a single document,
 *     such as start, will be ignored.
 * @return an abstraction of a raw index document to retrieve fields from.
 */
default Optional<FieldBundle> getRaw(K key, QueryOptions opts) {
    opts = opts.withStart(0).withLimit(2);
    ImmutableList<FieldBundle> results;
    try {
        results = getSource(keyPredicate(key), opts).readRaw().toList();
    } catch (QueryParseException e) {
        throw new StorageException("Unexpected QueryParseException during get()", e);
    }
    if (results.size() > 1) {
        throw new StorageException("Multiple results found in index for key " + key + ": " + results);
    }
    return results.stream().findFirst();
}
Also used : FieldBundle(com.google.gerrit.index.query.FieldBundle) StorageException(com.google.gerrit.exceptions.StorageException) QueryParseException(com.google.gerrit.index.query.QueryParseException)

Example 100 with StorageException

use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.

the class WorkInProgressOp method postUpdate.

@Override
public void postUpdate(PostUpdateContext ctx) {
    stateChanged.fire(ctx.getChangeData(change), ps, ctx.getAccount(), ctx.getWhen());
    NotifyResolver.Result notify = ctx.getNotify(change.getId());
    if (workInProgress || notify.handling().compareTo(NotifyHandling.OWNER_REVIEWERS) < 0 || !sendEmail) {
        return;
    }
    RepoView repoView;
    try {
        repoView = ctx.getRepoView();
    } catch (IOException ex) {
        throw new StorageException(String.format("Repository %s not found", ctx.getProject().get()), ex);
    }
    email.create(notify, notes, ps, ctx.getIdentifiedUser(), mailMessage, ctx.getWhen(), ImmutableList.of(), mailMessage, ImmutableList.of(), repoView).sendAsync();
}
Also used : IOException(java.io.IOException) StorageException(com.google.gerrit.exceptions.StorageException) RepoView(com.google.gerrit.server.update.RepoView)

Aggregations

StorageException (com.google.gerrit.exceptions.StorageException)153 IOException (java.io.IOException)68 Change (com.google.gerrit.entities.Change)47 ObjectId (org.eclipse.jgit.lib.ObjectId)37 Repository (org.eclipse.jgit.lib.Repository)33 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)30 PatchSet (com.google.gerrit.entities.PatchSet)29 RevCommit (org.eclipse.jgit.revwalk.RevCommit)28 ArrayList (java.util.ArrayList)25 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)24 Project (com.google.gerrit.entities.Project)22 Ref (org.eclipse.jgit.lib.Ref)22 ChangeData (com.google.gerrit.server.query.change.ChangeData)21 RevWalk (org.eclipse.jgit.revwalk.RevWalk)21 Account (com.google.gerrit.entities.Account)20 Inject (com.google.inject.Inject)19 Map (java.util.Map)19 Test (org.junit.Test)19 List (java.util.List)18 BranchNameKey (com.google.gerrit.entities.BranchNameKey)17