Skip to content

Commit

Permalink
Merge pull request opensearch-project#714 from peternied/pipe-exception
Browse files Browse the repository at this point in the history
Make sure exception cause is piped to PhaseFailed exception
  • Loading branch information
peternied authored Jun 10, 2024
2 parents c1c4383 + 669f0f9 commit 13211e2
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 10 deletions.
4 changes: 2 additions & 2 deletions RFS/src/main/java/com/rfs/RunRfsWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,15 @@ public static void main(String[] args) throws Exception {
documentsWorker.run();

} catch (Runner.PhaseFailed e) {
logPhaseFailureRecord(e.phase, e.nextStep, e.cmsEntry, e.e);
logPhaseFailureRecord(e.phase, e.nextStep, e.cmsEntry, e.getCause());
throw e;
} catch (Exception e) {
logger.error("Unexpected error running RfsWorker", e);
throw e;
}
}

public static void logPhaseFailureRecord(GlobalState.Phase phase, WorkerStep nextStep, Optional<CmsEntry.Base> cmsEntry, Exception e) {
public static void logPhaseFailureRecord(GlobalState.Phase phase, WorkerStep nextStep, Optional<CmsEntry.Base> cmsEntry, Throwable e) {
ObjectNode errorBlob = new ObjectMapper().createObjectNode();
errorBlob.put("exceptionMessage", e.getMessage());
errorBlob.put("exceptionClass", e.getClass().getSimpleName());
Expand Down
6 changes: 2 additions & 4 deletions RFS/src/main/java/com/rfs/worker/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ default void run() {
runInternal();
getLogger().info(getPhaseName() + " Phase is complete");
} catch (Exception e) {
getLogger().error(getPhaseName() + " Phase failed w/ an exception");
getLogger().error(getPhaseName() + " Phase failed w/ an exception ", e);

throw e;
}
Expand All @@ -28,14 +28,12 @@ public static class PhaseFailed extends RfsException {
public final GlobalState.Phase phase;
public final WorkerStep nextStep;
public final Optional<CmsEntry.Base> cmsEntry;
public final Exception e;

public PhaseFailed(String message, GlobalState.Phase phase, WorkerStep nextStep, Optional<CmsEntry.Base> cmsEntry, Exception e) {
super(message);
super(message, e);
this.phase = phase;
this.nextStep = nextStep;
this.cmsEntry = cmsEntry;
this.e = e;
}
}
}
2 changes: 1 addition & 1 deletion RFS/src/test/java/com/rfs/worker/DocumentsRunnerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ void run_encountersAnException_asExpected() {
assertEquals(GlobalState.Phase.DOCUMENTS_IN_PROGRESS, e.phase);
assertEquals(DocumentsStep.GetEntry.class, e.nextStep.getClass());
assertEquals(Optional.empty(), e.cmsEntry);
assertEquals(testException, e.e);
assertEquals(testException, e.getCause());
}
}
2 changes: 1 addition & 1 deletion RFS/src/test/java/com/rfs/worker/IndexRunnerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ void run_encountersAnException_asExpected() {
assertEquals(GlobalState.Phase.INDEX_IN_PROGRESS, e.phase);
assertEquals(IndexStep.GetEntry.class, e.nextStep.getClass());
assertEquals(Optional.empty(), e.cmsEntry);
assertEquals(testException, e.e);
assertEquals(testException, e.getCause());
}
}
2 changes: 1 addition & 1 deletion RFS/src/test/java/com/rfs/worker/MetadataRunnerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void run_encountersAnException_asExpected() {
assertEquals(GlobalState.Phase.METADATA_IN_PROGRESS, e.phase);
assertEquals(null, e.nextStep);
assertEquals(Optional.empty(), e.cmsEntry);
assertEquals(testException, e.e);
assertEquals(testException, e.getCause());
}

}
2 changes: 1 addition & 1 deletion RFS/src/test/java/com/rfs/worker/SnapshotRunnerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void run_encountersAnException_asExpected() {
assertEquals(GlobalState.Phase.SNAPSHOT_IN_PROGRESS, e.phase);
assertEquals(null, e.nextStep);
assertEquals(Optional.empty(), e.cmsEntry);
assertEquals(testException, e.e);
assertEquals(testException, e.getCause());
}

}

0 comments on commit 13211e2

Please sign in to comment.