From d039cfe6fa94f1033d9aaa8f72a62d5dbe37226f Mon Sep 17 00:00:00 2001 From: Edwin Kempin Date: Thu, 5 Dec 2019 10:26:57 +0100 Subject: [PATCH] InvalidRevisionException: Include invalid revision into message This way we know which revision was invalid when this exception gets logged. Signed-off-by: Edwin Kempin Change-Id: I0f693c63f32abc65bfb83574def1179896724ad9 --- .../google/gerrit/server/project/RefUtil.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/java/com/google/gerrit/server/project/RefUtil.java b/java/com/google/gerrit/server/project/RefUtil.java index 1dac751758..44c4f86c21 100644 --- a/java/com/google/gerrit/server/project/RefUtil.java +++ b/java/com/google/gerrit/server/project/RefUtil.java @@ -19,6 +19,7 @@ import static org.eclipse.jgit.lib.Constants.R_TAGS; import com.google.common.collect.Iterables; import com.google.common.flogger.FluentLogger; +import com.google.gerrit.common.Nullable; import com.google.gerrit.entities.Project; import com.google.gerrit.entities.RefNames; import com.google.gerrit.extensions.restapi.BadRequestException; @@ -46,16 +47,16 @@ public class RefUtil { try { ObjectId revid = repo.resolve(baseRevision); if (revid == null) { - throw new InvalidRevisionException(); + throw new InvalidRevisionException(baseRevision); } return revid; } catch (IOException err) { logger.atSevere().withCause(err).log( "Cannot resolve \"%s\" in project \"%s\"", baseRevision, projectName.get()); - throw new InvalidRevisionException(); + throw new InvalidRevisionException(baseRevision); } catch (RevisionSyntaxException err) { logger.atSevere().withCause(err).log("Invalid revision syntax \"%s\"", baseRevision); - throw new InvalidRevisionException(); + throw new InvalidRevisionException(baseRevision); } } @@ -66,7 +67,7 @@ public class RefUtil { try { rw.markStart(rw.parseCommit(revid)); } catch (IncorrectObjectTypeException err) { - throw new InvalidRevisionException(); + throw new InvalidRevisionException(revid.name()); } RefDatabase refDb = repo.getRefDatabase(); Iterable refs = @@ -86,11 +87,11 @@ public class RefUtil { rw.checkConnectivity(); return rw; } catch (IncorrectObjectTypeException | MissingObjectException err) { - throw new InvalidRevisionException(); + throw new InvalidRevisionException(revid.name()); } catch (IOException err) { logger.atSevere().withCause(err).log( "Repository \"%s\" may be corrupt; suggest running git fsck", repo.getDirectory()); - throw new InvalidRevisionException(); + throw new InvalidRevisionException(revid.name()); } } @@ -125,8 +126,8 @@ public class RefUtil { public static final String MESSAGE = "Invalid Revision"; - InvalidRevisionException() { - super(MESSAGE); + InvalidRevisionException(@Nullable String invalidRevision) { + super(MESSAGE + ": " + invalidRevision); } } }