@@ -155,6 +155,18 @@ def run(self, ctx: WorkflowContext): # type: ignore[no-untyped-def]
155155 raise ValueError ("something went wrong" )
156156
157157
158+ @workflow .defn (name = "construction-failing-workflow" )
159+ class ConstructionFailingWorkflow :
160+ def run (self , ctx : WorkflowContext ): # type: ignore[no-untyped-def]
161+ raise RuntimeError ("failed before first yield" )
162+
163+
164+ @workflow .defn (name = "construction-stop-iteration-workflow" )
165+ class ConstructionStopIterationWorkflow :
166+ def run (self , ctx : WorkflowContext ): # type: ignore[no-untyped-def]
167+ raise StopIteration ("stopped before first yield" )
168+
169+
158170@workflow .defn (name = "typed-compensation-failure-workflow" )
159171class TypedCompensationFailureWorkflow :
160172 def run (self , ctx : WorkflowContext ): # type: ignore[no-untyped-def]
@@ -848,6 +860,24 @@ def test_exception_produces_fail_command(self) -> None:
848860 assert cmd .exception_type == "ValueError"
849861 assert cmd .exception_class == "builtins.ValueError"
850862
863+ def test_non_generator_exception_produces_fail_command (self ) -> None :
864+ outcome = replay (ConstructionFailingWorkflow , [], [])
865+ assert len (outcome .commands ) == 1
866+ cmd = outcome .commands [0 ]
867+ assert isinstance (cmd , FailWorkflow )
868+ assert "failed before first yield" in cmd .message
869+ assert cmd .exception_type == "RuntimeError"
870+ assert cmd .exception_class == "builtins.RuntimeError"
871+
872+ def test_non_generator_stop_iteration_is_not_completion (self ) -> None :
873+ outcome = replay (ConstructionStopIterationWorkflow , [], [])
874+ assert len (outcome .commands ) == 1
875+ cmd = outcome .commands [0 ]
876+ assert isinstance (cmd , FailWorkflow )
877+ assert "stopped before first yield" in cmd .message
878+ assert cmd .exception_type == "StopIteration"
879+ assert cmd .exception_class == "builtins.StopIteration"
880+
851881 def test_fail_server_command_shape (self ) -> None :
852882 history = [{"event_type" : "ActivityCompleted" , "payload" : {"result" : '"ok"' }}]
853883 outcome = replay (FailingWorkflow , history , [])
0 commit comments