This is an automated email from the ASF dual-hosted git repository.

jason810496 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 4b25735cfcd Java SDK: Catch Throwable so task Errors are logged and 
fail cleanly (#68988)
4b25735cfcd is described below

commit 4b25735cfcd6c326969c69d887eac8eb6e527685
Author: PoAn Yang <[email protected]>
AuthorDate: Sat Jun 27 12:13:45 2026 +0900

    Java SDK: Catch Throwable so task Errors are logged and fail cleanly 
(#68988)
---
 .../main/kotlin/org/apache/airflow/sdk/execution/Task.kt |  2 +-
 .../kotlin/org/apache/airflow/sdk/execution/TaskTest.kt  | 16 ++++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git 
a/java-sdk/sdk/src/main/kotlin/org/apache/airflow/sdk/execution/Task.kt 
b/java-sdk/sdk/src/main/kotlin/org/apache/airflow/sdk/execution/Task.kt
index 8e26af77fee..60258dacc62 100644
--- a/java-sdk/sdk/src/main/kotlin/org/apache/airflow/sdk/execution/Task.kt
+++ b/java-sdk/sdk/src/main/kotlin/org/apache/airflow/sdk/execution/Task.kt
@@ -74,7 +74,7 @@ internal object TaskRunner {
     return try {
       
task.getDeclaredConstructor().newInstance().execute(Context.from(request), 
client)
       TaskResult.success()
-    } catch (e: Exception) {
+    } catch (e: Throwable) {
       logger.error("Error executing task", mapOf("ti" to request.ti, "error" 
to e, "trace" to e.stackTraceToString()))
       e.printStackTrace()
       if (request.tiContext.shouldRetry) {
diff --git 
a/java-sdk/sdk/src/test/kotlin/org/apache/airflow/sdk/execution/TaskTest.kt 
b/java-sdk/sdk/src/test/kotlin/org/apache/airflow/sdk/execution/TaskTest.kt
index 27d618e3c67..42a083b94aa 100644
--- a/java-sdk/sdk/src/test/kotlin/org/apache/airflow/sdk/execution/TaskTest.kt
+++ b/java-sdk/sdk/src/test/kotlin/org/apache/airflow/sdk/execution/TaskTest.kt
@@ -75,6 +75,15 @@ class TaskTest {
     Assertions.assertInstanceOf(RetryTask::class.java, result)
   }
 
+  @Test
+  @DisplayName("Should return failed when task throws an Error")
+  fun shouldReturnFailedWhenTaskThrowsError() {
+    val result = runTask(bundleWith("erroring", 
ErrorThrowingTask::class.java), startupDetails(taskId = "erroring"), 
noOpClient())
+
+    Assertions.assertInstanceOf(TaskState::class.java, result)
+    Assertions.assertEquals(TaskState.State.FAILED, (result as 
TaskState).state)
+  }
+
   private fun bundleWith(
     taskId: String,
     taskClass: Class<out Task>,
@@ -155,4 +164,11 @@ class TaskTest {
       client: Client,
     ): Unit = throw IllegalStateException("boom")
   }
+
+  class ErrorThrowingTask : Task {
+    override fun execute(
+      context: Context,
+      client: Client,
+    ): Unit = throw NoClassDefFoundError("simulated")
+  }
 }

Reply via email to