Browse Source

Move ServiceMayNotContinueException handling code from sendPack

All other exceptions are handled in a wrapped sendPack method.
Consolidate the error handling code.

Change-Id: Ieac0ce64960534d009d1e6b025130b021b744794
Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
stable-5.5
Masaya Suzuki 6 years ago committed by Terry Parker
parent
commit
3091dc4348
  1. 46
      org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

46
org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

@ -2078,12 +2078,22 @@ public class UploadPack {
try {
sendPack(true, req, accumulator, allTags, unshallowCommits,
deepenNots);
} catch (ServiceMayNotContinueException noPack) {
// This was already reported on (below).
throw noPack;
} catch (ServiceMayNotContinueException err) {
String message = err.getMessage();
if (message == null) {
message = JGitText.get().internalServerError;
}
try {
reportInternalServerErrorOverSideband(message);
} catch (IOException e) {
err.addSuppressed(e);
throw err;
}
throw new UploadPackInternalServerErrorException(err);
} catch (IOException | RuntimeException | Error err) {
try {
reportInternalServerErrorOverSideband();
reportInternalServerErrorOverSideband(
JGitText.get().internalServerError);
} catch (IOException e) {
err.addSuppressed(e);
throw err;
@ -2095,12 +2105,13 @@ public class UploadPack {
}
}
private void reportInternalServerErrorOverSideband() throws IOException {
private void reportInternalServerErrorOverSideband(String message)
throws IOException {
@SuppressWarnings("resource" /* java 7 */)
SideBandOutputStream err = new SideBandOutputStream(
SideBandOutputStream.CH_ERROR, SideBandOutputStream.SMALL_BUF,
rawOut);
err.write(Constants.encode(JGitText.get().internalServerError));
err.write(Constants.encode(message));
err.flush();
}
@ -2147,25 +2158,12 @@ public class UploadPack {
}
}
try {
if (wantAll.isEmpty()) {
preUploadHook.onSendPack(this, wantIds, commonBase);
} else {
preUploadHook.onSendPack(this, wantAll, commonBase);
}
msgOut.flush();
} catch (ServiceMayNotContinueException noPack) {
if (sideband && noPack.getMessage() != null) {
noPack.setOutput();
@SuppressWarnings("resource" /* java 7 */)
SideBandOutputStream err = new SideBandOutputStream(
SideBandOutputStream.CH_ERROR,
SideBandOutputStream.SMALL_BUF, rawOut);
err.write(Constants.encode(noPack.getMessage()));
err.flush();
}
throw noPack;
if (wantAll.isEmpty()) {
preUploadHook.onSendPack(this, wantIds, commonBase);
} else {
preUploadHook.onSendPack(this, wantAll, commonBase);
}
msgOut.flush();
PackConfig cfg = packConfig;
if (cfg == null)

Loading…
Cancel
Save