more descriptive error messages and exceptions (#9868)

* more descriptive error messages and exceptions
* Travis --> Kokoro
pull/9871/head
Elliotte Rusty Harold 3 years ago committed by GitHub
parent 37b782198c
commit d2b669a4dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      conformance/ConformanceJava.java
  2. 2
      conformance/README.md

@ -229,11 +229,12 @@ class ConformanceJava {
} }
private Conformance.ConformanceResponse doTest(Conformance.ConformanceRequest request) { private Conformance.ConformanceResponse doTest(Conformance.ConformanceRequest request) {
com.google.protobuf.AbstractMessage testMessage; AbstractMessage testMessage;
String messageType = request.getMessageType();
boolean isProto3 = boolean isProto3 =
request.getMessageType().equals("protobuf_test_messages.proto3.TestAllTypesProto3"); messageType.equals("protobuf_test_messages.proto3.TestAllTypesProto3");
boolean isProto2 = boolean isProto2 =
request.getMessageType().equals("protobuf_test_messages.proto2.TestAllTypesProto2"); messageType.equals("protobuf_test_messages.proto2.TestAllTypesProto2");
switch (request.getPayloadCase()) { switch (request.getPayloadCase()) {
case PROTOBUF_PAYLOAD: case PROTOBUF_PAYLOAD:
@ -263,7 +264,8 @@ class ConformanceJava {
.build(); .build();
} }
} else { } else {
throw new RuntimeException("Protobuf request doesn't have specific payload type."); throw new IllegalArgumentException(
"Protobuf request has unexpected payload type: " + messageType);
} }
break; break;
} }
@ -286,7 +288,8 @@ class ConformanceJava {
parser.merge(request.getJsonPayload(), builder); parser.merge(request.getJsonPayload(), builder);
testMessage = builder.build(); testMessage = builder.build();
} else { } else {
throw new RuntimeException("Protobuf request doesn't have specific payload type."); throw new IllegalArgumentException(
"Protobuf request has unexpected payload type: " + messageType);
} }
} catch (InvalidProtocolBufferException e) { } catch (InvalidProtocolBufferException e) {
return Conformance.ConformanceResponse.newBuilder() return Conformance.ConformanceResponse.newBuilder()
@ -320,24 +323,25 @@ class ConformanceJava {
.build(); .build();
} }
} else { } else {
throw new RuntimeException("Protobuf request doesn't have specific payload type."); throw new IllegalArgumentException(
"Protobuf request has unexpected payload type: " + messageType);
} }
break; break;
} }
case PAYLOAD_NOT_SET: case PAYLOAD_NOT_SET:
{ {
throw new RuntimeException("Request didn't have payload."); throw new IllegalArgumentException("Request didn't have payload.");
} }
default: default:
{ {
throw new RuntimeException("Unexpected payload case."); throw new IllegalArgumentException("Unexpected payload case.");
} }
} }
switch (request.getRequestedOutputFormat()) { switch (request.getRequestedOutputFormat()) {
case UNSPECIFIED: case UNSPECIFIED:
throw new RuntimeException("Unspecified output format."); throw new IllegalArgumentException("Unspecified output format.");
case PROTOBUF: case PROTOBUF:
{ {
@ -366,7 +370,7 @@ class ConformanceJava {
default: default:
{ {
throw new RuntimeException("Unexpected request output."); throw new IllegalArgumentException("Unexpected request output.");
} }
} }
} }

@ -49,7 +49,7 @@ Running the tests for other languages
Most of the languages in the Protobuf source tree are set up to run Most of the languages in the Protobuf source tree are set up to run
conformance tests. However some of them are more tricky to set up conformance tests. However some of them are more tricky to set up
properly. See `tests.sh` in the base of the repository to see how properly. See `tests.sh` in the base of the repository to see how
Travis runs the tests. Kokoro runs the tests.
Testing other Protocol Buffer implementations Testing other Protocol Buffer implementations
--------------------------------------------- ---------------------------------------------

Loading…
Cancel
Save