Report PackProtocolExceptions to client during receive-pack

We have done this since forever with the "wanted old new ref" error,
so let's do it for other such errors thrown in the same block as well.

Change-Id: Ib3b1c7f05e31a5b3e40e85eb07b16736920a033b
This commit is contained in:
Dave Borowitz 2015-07-01 11:24:25 -07:00
parent a643aaaa4a
commit 6e4e34bb9e
3 changed files with 55 additions and 49 deletions

View File

@ -76,6 +76,7 @@
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.errors.PackProtocolException;
import org.eclipse.jgit.errors.UnpackException; import org.eclipse.jgit.errors.UnpackException;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.InternalHttpServerGlue; import org.eclipse.jgit.transport.InternalHttpServerGlue;
@ -200,7 +201,7 @@ public void flush() throws IOException {
consumeRequestBody(req); consumeRequestBody(req);
out.close(); out.close();
} catch (UnpackException e) { } catch (UnpackException | PackProtocolException e) {
// This should be already reported to the client. // This should be already reported to the client.
log(rp.getRepository(), e.getCause()); log(rp.getRepository(), e.getCause());
consumeRequestBody(req); consumeRequestBody(req);

View File

@ -60,7 +60,7 @@ public class PackProtocolException extends TransportException {
* @param uri * @param uri
* URI used for transport * URI used for transport
* @param s * @param s
* message * message, which may be shown to an end-user.
*/ */
public PackProtocolException(final URIish uri, final String s) { public PackProtocolException(final URIish uri, final String s) {
super(uri + ": " + s); //$NON-NLS-1$ super(uri + ": " + s); //$NON-NLS-1$
@ -73,7 +73,7 @@ public PackProtocolException(final URIish uri, final String s) {
* @param uri * @param uri
* URI used for transport * URI used for transport
* @param s * @param s
* message * message, which may be shown to an end-user.
* @param cause * @param cause
* root cause exception * root cause exception
*/ */
@ -86,7 +86,7 @@ public PackProtocolException(final URIish uri, final String s,
* Constructs an PackProtocolException with the specified detail message. * Constructs an PackProtocolException with the specified detail message.
* *
* @param s * @param s
* message * message, which may be shown to an end-user.
*/ */
public PackProtocolException(final String s) { public PackProtocolException(final String s) {
super(s); super(s);
@ -96,7 +96,7 @@ public PackProtocolException(final String s) {
* Constructs an PackProtocolException with the specified detail message. * Constructs an PackProtocolException with the specified detail message.
* *
* @param s * @param s
* message * message, which may be shown to an end-user.
* @param cause * @param cause
* root cause exception * root cause exception
*/ */

View File

@ -1065,6 +1065,7 @@ public void sendAdvertisedRefs(final RefAdvertiser adv)
protected void recvCommands() throws IOException { protected void recvCommands() throws IOException {
PushCertificateParser certParser = getPushCertificateParser(); PushCertificateParser certParser = getPushCertificateParser();
FirstLine firstLine = null; FirstLine firstLine = null;
try {
for (;;) { for (;;) {
String line; String line;
try { try {
@ -1116,6 +1117,10 @@ protected void recvCommands() throws IOException {
certParser.addCommand(cmd); certParser.addCommand(cmd);
} }
} }
} catch (PackProtocolException e) {
sendError(e.getMessage());
throw e;
}
} }
static ReceiveCommand parseCommand(String line) throws PackProtocolException { static ReceiveCommand parseCommand(String line) throws PackProtocolException {