You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "FrankYang0529 (via GitHub)" <gi...@apache.org> on 2026/08/03 06:15:53 UTC

Re: [PR] Java SDK: Clearer error when a task class cannot be instantiated [airflow]

FrankYang0529 commented on code in PR #69827:
URL: https://github.com/apache/airflow/pull/69827#discussion_r3701715398


##########
java-sdk/sdk/src/main/kotlin/org/apache/airflow/sdk/execution/Task.kt:
##########
@@ -71,17 +74,29 @@ internal object TaskRunner {
     client: Client,
   ): Any {
     val task = bundle.dags[request.ti.dagId]?.tasks[request.ti.taskId] ?: return TaskResult.of(TaskState.State.REMOVED)
+    val instance =
+      try {
+        task.getDeclaredConstructor().newInstance()
+      } catch (e: InvocationTargetException) {
+        val cause = e.cause ?: e
+        logger.error(
+          "Task class constructor threw an exception",
+          mapOf("ti" to request.ti, "taskClass" to task.name, "error" to cause, "trace" to cause.stackTraceToString()),
+        )
+        return TaskResult.failure(request.tiContext.shouldRetry)
+      } catch (e: Throwable) {
+        logger.error(
+          "Cannot instantiate task class. A task class must be concrete and declare a public no-argument constructor",
+          mapOf("ti" to request.ti, "taskClass" to task.name, "error" to e, "trace" to e.stackTraceToString()),
+        )
+        return TaskResult.failure(request.tiContext.shouldRetry)
+      }

Review Comment:
   Good catch. Chnaged to use `TaskResult.failure(shouldRetry = false)` here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org