Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store entire Throwable in ErrorDetail class #1217

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public <T extends Serializable> T executeOrThrowException(
ErrorDetail.builder()
.setId(idempotentId)
.setTitle(itemName)
.setException(Throwables.getStackTraceAsString(e))
.setThrowable(e)
.build();
addError(idempotentId, errorDetail);
monitor.severe(() -> jobIdPrefix + "Problem with importing item: " + errorDetail);
Expand Down Expand Up @@ -232,6 +232,8 @@ private Entity createErrorEntity(String idempotentId, ErrorDetail error) throws
@VisibleForTesting
Entity createErrorEntity(String idempotentId, UUID jobId, ErrorDetail error)
throws IOException {
System.out.println("AQAQAQAQ");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO delete this

System.out.println(objectMapper.writeValueAsString(error));
return GoogleCloudUtils.createEntityBuilder(
getErrorKey(idempotentId, jobId),
ImmutableMap.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void loadCachedValuesFromDataStore() throws Exception {
assertEquals(googleExecutor.getCachedValue("id3"), "idempotentId3");
assertEquals(googleExecutor.getErrors().size(), 1);
assertTrue(googleExecutor.getErrors().contains(
ErrorDetail.builder().setId("id4").setTitle("title").setException("error").build()));
ErrorDetail.builder().setId("id4").setTitle("title").setThrowable(new IOException("error")).build()));

// we shouldn't load any items belonging to JOB_ID_2
assertFalse(googleExecutor.isKeyCached("id1_job2"));
Expand All @@ -68,7 +68,7 @@ public void removeErrorIfItemSucceeds() throws Exception {
initializeDS();
googleExecutor.setJobId(JOB_ID);
assertTrue(googleExecutor.getErrors().contains(
ErrorDetail.builder().setId("id4").setTitle("title").setException("error").build()));
ErrorDetail.builder().setId("id4").setTitle("title").setThrowable(new IOException("error")).build()));

// now execute a successful import of id4
googleExecutor.executeAndSwallowIOExceptions("id4", ITEM_NAME, () -> "idempotentId4");
Expand All @@ -86,7 +86,7 @@ private void initializeDS() throws IOException {
t.put(googleExecutor.createResultEntity("id2", JOB_ID, "idempotentId2"));
t.put(googleExecutor.createResultEntity("id3", JOB_ID, "idempotentId3"));
t.put(googleExecutor.createErrorEntity("id4", JOB_ID,
ErrorDetail.builder().setId("id4").setTitle("title").setException("error").build()));
ErrorDetail.builder().setId("id4").setTitle("title").setThrowable(new IOException("error")).build()));

t.put(googleExecutor.createResultEntity("id1_job2", JOB_ID_2, "idempotentId1_job2"));
t.commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public <T extends Serializable> T executeOrThrowException(
ErrorDetail.builder()
.setId(idempotentId)
.setTitle(itemName)
.setException(Throwables.getStackTraceAsString(e))
.setThrowable(e)
.build();
errors.put(idempotentId, errorDetail);
recentErrors.put(idempotentId, errorDetail);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ public static ErrorDetail.Builder builder() {
public abstract String title();

@JsonProperty("exception")
public abstract String exception();
public String exception() {
return Throwables.getStackTraceAsString(throwable());
}

public abstract Throwable throwable();

@AutoValue.Builder
public abstract static class Builder {
Expand All @@ -63,7 +67,6 @@ private static ErrorDetail.Builder create() {
@JsonProperty("title")
public abstract Builder setTitle(String title);

@JsonProperty("exception")
public abstract Builder setException(String exception);
public abstract Builder setThrowable(Throwable throwable);
}
}