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 7c406053934 TS SDK: Report a task failure when the handler throws 
undefined or null (#77379)
7c406053934 is described below

commit 7c406053934372a01ff655d58ac47547dace75ad
Author: Adam Postek <[email protected]>
AuthorDate: Wed Nov 25 12:48:47 2026 +0000

    TS SDK: Report a task failure when the handler throws undefined or null 
(#77379)
    
    * TS SDK: Report a task failure when the handler throws undefined or null
    
    Signed-off-by: Adam <[email protected]>
    
    * TS SDK: Cover a thrown object whose message is not a string
    
    Signed-off-by: Adam <[email protected]>
    
    ---------
    
    Signed-off-by: Adam <[email protected]>
---
 ts-sdk/src/coordinator/runtime.ts            | 18 ++++++++++++------
 ts-sdk/tests/coordinator/integration.test.ts | 18 ++++++++++++++++++
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/ts-sdk/src/coordinator/runtime.ts 
b/ts-sdk/src/coordinator/runtime.ts
index 742cd02ea02..dbd3dd2cb2b 100644
--- a/ts-sdk/src/coordinator/runtime.ts
+++ b/ts-sdk/src/coordinator/runtime.ts
@@ -314,7 +314,7 @@ function handleParse(
         },
       });
     } catch (err) {
-      const detail = err instanceof Error ? err.message : String(err);
+      const detail = errorMessage(err);
       logs.error("Dag could not be serialized", { dag_id: dag.dagId, detail });
       failures.push(`Dag "${dag.dagId}": ${detail}`);
     }
@@ -386,7 +386,7 @@ async function handleTask(
         );
     }
   } catch (err) {
-    return fail((err as Error).message ?? String(err));
+    return fail(errorMessage(err));
   }
 }
 
@@ -408,7 +408,7 @@ async function runHandler(
     });
   } catch (err) {
     // Before the handler ran, so nothing it might have written is at stake.
-    const message = (err as Error).message ?? String(err);
+    const message = errorMessage(err);
     logs.error("Cannot bind this task's call arguments", {
       task_id: ctx.taskId,
       error: message,
@@ -438,11 +438,11 @@ async function runHandler(
     };
     return response;
   } catch (err) {
-    const message = (err as Error).message ?? String(err);
+    const message = errorMessage(err);
     logs.error("Task failed", {
       task_id: ctx.taskId,
       error: message,
-      stack: (err as Error).stack ?? null,
+      stack: (err as { stack?: unknown } | null | undefined)?.stack ?? null,
       // A handler that destructured a bound argument under a name nothing
       // folds to gets no error of its own, so a failing task says what its
       // call actually delivered.
@@ -464,7 +464,7 @@ async function sendSupervisorResponse(
   } catch (err) {
     logs.error("Failed to send response to supervisor", {
       response_type: responseType(body),
-      error: (err as Error).message ?? String(err),
+      error: errorMessage(err),
     });
     throw err;
   }
@@ -489,6 +489,12 @@ function buildFailureResponse(
   };
 }
 
+// User code can throw anything, including undefined, null or an Error from 
another realm.
+function errorMessage(err: unknown): string {
+  const message = (err as { message?: unknown } | null | undefined)?.message;
+  return typeof message === "string" ? message : String(err);
+}
+
 function responseType(body: unknown): string {
   if (body && typeof body === "object" && "type" in body) {
     const type = (body as { type?: unknown }).type;
diff --git a/ts-sdk/tests/coordinator/integration.test.ts 
b/ts-sdk/tests/coordinator/integration.test.ts
index e970138247d..0e713209632 100644
--- a/ts-sdk/tests/coordinator/integration.test.ts
+++ b/ts-sdk/tests/coordinator/integration.test.ts
@@ -413,6 +413,24 @@ describe("coordinator runtime integration", () => {
     });
   });
 
+  it.each([
+    [undefined, "undefined"],
+    [null, "null"],
+    ["disk full", "disk full"],
+    [{ message: "quota exceeded", code: 429 }, "quota exceeded"],
+    [{ message: 429 }, "[object Object]"],
+  ])("returns RetryTask when the handler throws %s", async (thrown, reason) => 
{
+    testDag.task("throws_non_error", async () => {
+      throw thrown;
+    })();
+
+    const result = await driveSupervisor(
+      makeStartupDetails("throws_non_error", "test_dag", "r1", { should_retry: 
true }),
+    );
+
+    expect(result.firstResponse!.body).toMatchObject({ type: "RetryTask", 
retry_reason: reason });
+  });
+
   it("dispatches to a task handler registered for a Python-owned Dag", async 
() => {
     // The mixed-language path: no Dag object exists for `py_dag` on this side,
     // only a handler bound to its dag_id and task_id.

Reply via email to