core: move exception to listener for RuntimeException, Error still throws

This commit is contained in:
Carl Mastrangelo 2017-12-05 10:29:04 -08:00 committed by GitHub
parent c9b02db276
commit 01ea67f5cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 9 deletions

View File

@ -137,10 +137,11 @@ final class ServerCallImpl<ReqT, RespT> extends ServerCall<ReqT, RespT> {
stream.flush();
} catch (RuntimeException e) {
close(Status.fromThrowable(e), new Metadata());
} catch (Error e) {
close(
Status.CANCELLED.withDescription("Server sendMessage() failed with Error"),
new Metadata());
throw e;
} catch (Throwable t) {
close(Status.fromThrowable(t), new Metadata());
throw new RuntimeException(t);
}
}

View File

@ -158,12 +158,7 @@ public class ServerCallImplTest {
call.sendHeaders(new Metadata());
doThrow(new RuntimeException("bad")).when(stream).writeMessage(isA(InputStream.class));
try {
call.sendMessage(1234L);
fail();
} catch (RuntimeException e) {
// expected
}
call.sendMessage(1234L);
verify(stream).close(isA(Status.class), isA(Metadata.class));
}