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>
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user