Skip to content

Commit

Permalink
Remove root cause extraction
Browse files Browse the repository at this point in the history
Signed-off-by: Chen Dai <[email protected]>
  • Loading branch information
dai-chen committed Jun 26, 2024
1 parent ed105c9 commit a4b4fe7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public T commit(Function<FlintMetadataLogEntry, T> operation) {
} catch (Exception ex) {
LOG.log(WARNING, "Failed to rollback transient log", ex);
}
throw new IllegalStateException("Failed to commit transaction operation");
throw new IllegalStateException("Failed to commit transaction operation", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,10 @@ trait FlintSparkTransactionSupport { self: Logging =>
result
} catch {
case e: Exception =>
// Extract and add root cause message to final error message
val rootCauseMessage = extractRootCause(e)
val detailedMessage =
s"Failed to execute index operation [$opName $indexName] caused by: $rootCauseMessage"
logError(detailedMessage, e)
logError(s"Failed to execute index operation [$opName $indexName]", e)

// Re-throw with new detailed error message
throw new IllegalStateException(detailedMessage)
// Rethrowing the original exception for high level logic to handle
throw e
}
}

private def extractRootCause(e: Throwable): String = {
var cause = e
while (cause.getCause != null && cause.getCause != cause) {
cause = cause.getCause
}

if (cause.getLocalizedMessage != null) {
return cause.getLocalizedMessage
}
if (cause.getMessage != null) {
return cause.getMessage
}
cause.toString
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,13 @@ class FlintSparkTransactionSupportSuite extends FlintSuite with Matchers {
verify(mockFlintMetadataLogService, times(1)).startTransaction(testIndex, true)
}

test("should throw exception with nested exception message") {
the[IllegalStateException] thrownBy {
transactionSupport.withTransaction[Unit](testIndex, testOpName) { _ =>
throw new IllegalArgumentException("Fake exception")
}
} should have message
s"Failed to execute index operation [test operation $testIndex] caused by: Fake exception"
}

test("should throw exception with root cause exception message") {
the[IllegalStateException] thrownBy {
test("should throw original exception") {
the[RuntimeException] thrownBy {
transactionSupport.withTransaction[Unit](testIndex, testOpName) { _ =>
val rootCause = new IllegalArgumentException("Fake root cause")
val cause = new RuntimeException("message ignored", rootCause)
throw new IllegalStateException("message ignored", cause)
val cause = new RuntimeException("Fake cause", rootCause)
throw cause
}
} should have message
s"Failed to execute index operation [test operation $testIndex] caused by: Fake root cause"
} should have message "Fake cause"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class FlintSparkTransactionITSuite extends OpenSearchTransactionSuite with Match
the[IllegalStateException] thrownBy {
flint.vacuumIndex(testFlintIndex)
} should have message
s"Failed to execute index operation [Vacuum Flint index $testFlintIndex] caused by: Index state [active] doesn't satisfy precondition"
s"Index state [active] doesn't satisfy precondition"
}

test("should not recreate index if index data still exists") {
Expand All @@ -209,7 +209,7 @@ class FlintSparkTransactionITSuite extends OpenSearchTransactionSuite with Match
.addValueSet("name")
.create()
} should have message
s"Failed to execute index operation [Create Flint index $testFlintIndex] caused by: Flint index $testFlintIndex already exists"
s"Flint index $testFlintIndex already exists"
}

test("should clean up metadata log entry if index data has been deleted") {
Expand Down

0 comments on commit a4b4fe7

Please sign in to comment.