Do not log 'Object too large' as error with full stacktrace

If a user pushes an object which is larger than the configured
receive.maxObjectSizeLimit parameter, the push is rejected with an
'Object too large' error. In addition an error log entry with the full
stacktrace is written into the error log.

This is not really a server error, but just a user doing something that
is not allowed, and thus it should not be logged as error. For a Gerrit
administrator it might still be interesting how often the limit is hit.
This is why it makes sense to still log this on info level.

For the user pushing a too large object we now do not print the
'fatal: Unpack error, check server log' message anymore, but only the
'Object too large' error message.

Change-Id: I5b7228f9b2ce41614712fde4ecd85525de3901a7
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2012-06-20 09:36:02 +02:00
parent 6355d915cd
commit 92edc8e481

View File

@@ -30,9 +30,10 @@ import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.transport.AdvertiseRefsHook;
import org.eclipse.jgit.transport.ReceivePack;
import org.kohsuke.args4j.Option;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -41,6 +42,8 @@ import java.util.Set;
/** Receives change upload over SSH using the Git receive-pack protocol. */
final class Receive extends AbstractGitCommand {
private static final Logger log = LoggerFactory.getLogger(Receive.class);
@Inject
private AsyncReceiveCommits.Factory factory;
@@ -98,9 +101,17 @@ final class Receive extends AbstractGitCommand {
// is larger than the receive.maxObjectSizeLimit gerrit.config parameter
// we want to present this error to the user
if (badStream.getCause() instanceof TooLargeObjectInPackException) {
PrintWriter p = toPrintWriter(err);
p.print("error: " + badStream.getCause().getMessage() + "\n");
p.flush();
StringBuilder msg = new StringBuilder();
msg.append("Receive error on project \""
+ projectControl.getProject().getName() + "\"");
msg.append(" (user ");
msg.append(currentUser.getAccount().getUserName());
msg.append(" account ");
msg.append(currentUser.getAccountId());
msg.append("): ");
msg.append(badStream.getCause().getMessage());
log.info(msg.toString());
throw new UnloggedFailure(128, "error: " + badStream.getCause().getMessage());
}
// This may have been triggered by branch level access controls.