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>
This commit is contained in:
parent
f8267c9edb
commit
3091dc4348
|
@ -2078,12 +2078,22 @@ private void sendPack(PackStatistics.Accumulator accumulator,
|
|||
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 @@ private void sendPack(PackStatistics.Accumulator accumulator,
|
|||
}
|
||||
}
|
||||
|
||||
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 @@ private void sendPack(final boolean sideband,
|
|||
}
|
||||
}
|
||||
|
||||
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…
Reference in New Issue