summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdwin Kempin <edwin.kempin@sap.com>2012-06-12 13:44:55 +0200
committerEdwin Kempin <edwin.kempin@sap.com>2012-06-12 14:49:17 +0200
commitb4ecc4016829d56544025d58bd3fbe50d3c7ee22 (patch)
tree04d321a7bbba10e542eca871c3b3ed84c396ed59
parentc347a0b534d9fef53c2056254ee88da8e4e88b86 (diff)
Display proper error if file diff fails because content is too large
File diffs can only be displayed for files that do not exceed a threshold for big files. If a file is larger, building the patch script fails with org.eclipse.jgit.errors.LargeObjectException. Since org.eclipse.jgit.errors.LargeObjectException is a RuntimeException the GerritJsonServlet treats it as internal failure and as result the web ui just shows 'Internal Server Error'. This change ensures that a proper error message is displayed in this case. This is done by wrapping the org.eclipse.jgit.errors.LargeObjectException into a normal Exception. Change-Id: I708957a2fadfce88f3c0c6a433343274ae169b6f Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
-rw-r--r--gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/PatchScriptFactory.java6
-rw-r--r--gerrit-server/src/main/java/com/google/gerrit/server/git/LargeObjectException.java33
2 files changed, 38 insertions, 1 deletions
diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/PatchScriptFactory.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/PatchScriptFactory.java
index 66b32785b9..d61e6e755f 100644
--- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/PatchScriptFactory.java
+++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/PatchScriptFactory.java
@@ -31,6 +31,7 @@ import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.AccountInfoCacheFactory;
import com.google.gerrit.server.git.GitRepositoryManager;
+import com.google.gerrit.server.git.LargeObjectException;
import com.google.gerrit.server.patch.PatchList;
import com.google.gerrit.server.patch.PatchListCache;
import com.google.gerrit.server.patch.PatchListEntry;
@@ -120,7 +121,8 @@ class PatchScriptFactory extends Handler<PatchScript> {
}
@Override
- public PatchScript call() throws OrmException, NoSuchChangeException {
+ public PatchScript call() throws OrmException, NoSuchChangeException,
+ LargeObjectException {
validatePatchSetId(psa);
validatePatchSetId(psb);
@@ -156,6 +158,8 @@ class PatchScriptFactory extends Handler<PatchScript> {
} catch (IOException e) {
log.error("File content unavailable", e);
throw new NoSuchChangeException(changeId, e);
+ } catch (org.eclipse.jgit.errors.LargeObjectException err) {
+ throw new LargeObjectException("File content is too large", err);
}
} finally {
git.close();
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/LargeObjectException.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/LargeObjectException.java
new file mode 100644
index 0000000000..d08b87683e
--- /dev/null
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/LargeObjectException.java
@@ -0,0 +1,33 @@
+// Copyright (C) 2012 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.gerrit.server.git;
+
+/**
+ * Wrapper for {@link org.eclipse.jgit.errors.LargeObjectException}. Since
+ * org.eclipse.jgit.errors.LargeObjectException is a {@link RuntimeException}
+ * the GerritJsonServlet would treat it as internal failure and as result the
+ * web ui would just show 'Internal Server Error'. Wrapping
+ * org.eclipse.jgit.errors.LargeObjectException into a normal {@link Exception}
+ * allows to display a proper error message.
+ */
+public class LargeObjectException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ public LargeObjectException(final String message,
+ final org.eclipse.jgit.errors.LargeObjectException cause) {
+ super(message, cause);
+ }
+}