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

Loading…
Cancel
Save