Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private int drainStartStream(
DynamicMessage end = (DynamicMessage) pe.getField(peEndF);
Descriptors.FieldDescriptor ec =
end.getDescriptorForType().findFieldByName("exit_code");
if (end.hasField(ec)) {
if (ec != null) {
Object v = end.getField(ec);
exit = v instanceof Integer ? (Integer) v : ((Long) v).intValue();
}
Expand Down Expand Up @@ -344,8 +344,6 @@ private DynamicMessage parseJsonStartResponse(byte[] data) throws IOException {
JsonNode exitCodeNode = endNode.path("exitCode");
if (exitCodeNode.canConvertToInt()) {
endBuilder.setField(exitCodeField, exitCodeNode.intValue());
}
if (!endBuilder.getAllFields().isEmpty()) {
event.setField(processEventDesc.findFieldByName("end"), endBuilder.build());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@ void jsonCodecReturnsEmptyOutputsWhenOnlyEndPresent() throws Exception {
assertEquals("", stderr.toString(StandardCharsets.UTF_8));
}

@Test
void jsonCodecPreservesZeroExitCode() throws Exception {
E2bEnvdProcessClient client = new E2bEnvdProcessClient(options(E2bCodec.JSON));
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
ByteArrayOutputStream stderr = new ByteArrayOutputStream();
int exit =
drainStartStream(client, connectFrame(responseJson(null, null, 0)), stdout, stderr);

assertEquals(0, exit);
}

private static DynamicMessage dataResponse(
E2bEnvdProcessClient client, String stdout, String stderr) {
Descriptors.FileDescriptor fd = client.fileDescriptor();
Expand Down
Loading