Skip to content

Commit

Permalink
updated stacktrace format in java trace messages (#13847)
Browse files Browse the repository at this point in the history
* updated stacktrace format in java trace messages

* test checks specifically on stacktrace in trace message

* remove unused import
  • Loading branch information
Phlair committed Jun 16, 2022
1 parent 34e2dc3 commit da95f50
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import io.airbyte.protocol.models.AirbyteMessage;
import io.airbyte.protocol.models.AirbyteMessage.Type;
import io.airbyte.protocol.models.AirbyteTraceMessage;
import java.util.Arrays;
import java.util.function.Consumer;
import org.apache.commons.lang3.exception.ExceptionUtils;

public final class AirbyteTraceMessageUtility {

Expand Down Expand Up @@ -53,7 +53,7 @@ private static AirbyteMessage makeErrorTraceAirbyteMessage(
.withFailureType(failureType)
.withMessage(displayMessage)
.withInternalMessage(e.toString())
.withStackTrace(Arrays.toString(e.getStackTrace()))));
.withStackTrace(ExceptionUtils.getStackTrace(e))));
}

private static AirbyteMessage makeAirbyteMessageFromTraceMessage(AirbyteTraceMessage airbyteTraceMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@ private void assertJsonNodeIsTraceMessage(JsonNode jsonNode) {
@Test
void testEmitSystemErrorTrace() {
AirbyteTraceMessageUtility.emitSystemErrorTrace(Mockito.mock(RuntimeException.class), "this is a system error");
assertJsonNodeIsTraceMessage(Jsons.deserialize(outContent.toString(StandardCharsets.UTF_8)));
JsonNode outJson = Jsons.deserialize(outContent.toString(StandardCharsets.UTF_8));
assertJsonNodeIsTraceMessage(outJson);
Assertions.assertEquals("system_error", outJson.get("trace").get("error").get("failure_type").asText());
}

@Test
void testEmitConfigErrorTrace() {
AirbyteTraceMessageUtility.emitConfigErrorTrace(Mockito.mock(RuntimeException.class), "this is a config error");
assertJsonNodeIsTraceMessage(Jsons.deserialize(outContent.toString(StandardCharsets.UTF_8)));
JsonNode outJson = Jsons.deserialize(outContent.toString(StandardCharsets.UTF_8));
assertJsonNodeIsTraceMessage(outJson);
Assertions.assertEquals("config_error", outJson.get("trace").get("error").get("failure_type").asText());
}

@Test
Expand All @@ -51,6 +55,17 @@ void testEmitErrorTrace() {
assertJsonNodeIsTraceMessage(Jsons.deserialize(outContent.toString(StandardCharsets.UTF_8)));
}

@Test
void testCorrectStacktraceFormat() {
try {
int x = 1 / 0;
} catch (Exception e) {
AirbyteTraceMessageUtility.emitSystemErrorTrace(e, "you exploded the universe");
}
JsonNode outJson = Jsons.deserialize(outContent.toString(StandardCharsets.UTF_8));
Assertions.assertTrue(outJson.get("trace").get("error").get("stack_trace").asText().contains("\n\tat"));
}

@AfterEach
public void revertOut() {
System.setOut(originalOut);
Expand Down

0 comments on commit da95f50

Please sign in to comment.