From a4b4fe7e2b58175ce7f2a100c955de15fd9b77ac Mon Sep 17 00:00:00 2001 From: Chen Dai Date: Wed, 26 Jun 2024 13:58:29 -0700 Subject: [PATCH] Remove root cause extraction Signed-off-by: Chen Dai --- .../log/DefaultOptimisticTransaction.java | 2 +- .../spark/FlintSparkTransactionSupport.scala | 25 +++---------------- .../FlintSparkTransactionSupportSuite.scala | 20 ++++----------- .../spark/FlintSparkTransactionITSuite.scala | 4 +-- 4 files changed, 11 insertions(+), 40 deletions(-) diff --git a/flint-core/src/main/scala/org/opensearch/flint/core/metadata/log/DefaultOptimisticTransaction.java b/flint-core/src/main/scala/org/opensearch/flint/core/metadata/log/DefaultOptimisticTransaction.java index 857ad656d..bfe99c0cd 100644 --- a/flint-core/src/main/scala/org/opensearch/flint/core/metadata/log/DefaultOptimisticTransaction.java +++ b/flint-core/src/main/scala/org/opensearch/flint/core/metadata/log/DefaultOptimisticTransaction.java @@ -126,7 +126,7 @@ public T commit(Function 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); } } diff --git a/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/FlintSparkTransactionSupport.scala b/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/FlintSparkTransactionSupport.scala index 27c91efe5..045c527c5 100644 --- a/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/FlintSparkTransactionSupport.scala +++ b/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/FlintSparkTransactionSupport.scala @@ -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 - } } diff --git a/flint-spark-integration/src/test/scala/org/opensearch/flint/spark/FlintSparkTransactionSupportSuite.scala b/flint-spark-integration/src/test/scala/org/opensearch/flint/spark/FlintSparkTransactionSupportSuite.scala index 129d46ec7..7646dde60 100644 --- a/flint-spark-integration/src/test/scala/org/opensearch/flint/spark/FlintSparkTransactionSupportSuite.scala +++ b/flint-spark-integration/src/test/scala/org/opensearch/flint/spark/FlintSparkTransactionSupportSuite.scala @@ -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" } } diff --git a/integ-test/src/test/scala/org/opensearch/flint/spark/FlintSparkTransactionITSuite.scala b/integ-test/src/test/scala/org/opensearch/flint/spark/FlintSparkTransactionITSuite.scala index 75ad970d2..741db4bd1 100644 --- a/integ-test/src/test/scala/org/opensearch/flint/spark/FlintSparkTransactionITSuite.scala +++ b/integ-test/src/test/scala/org/opensearch/flint/spark/FlintSparkTransactionITSuite.scala @@ -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") { @@ -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") {