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);
}
}
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);
}
}
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();
}
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();
}
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();
}
Aggregations