You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to structure workflows in an easy-to-read and understandable manner, especially when the workflow's code is long enough. At my company, we have found that it is easier when we move the part of code that is related to the same action, or part of the flow (activity calls, timers, if statements) into a private function inside the workflow code. Thus we create private methods inside workflow classes that return Generators (simply because of the yield inside that method)
Describe the bug
When an exception is thrown in the generator it returns null instead of throwing that exception in the outer scope, which results in proceeding workflow execution instead of immediate cancel of workflow. See comparison below
By running the example above we get the workflow in completed status, even though the activity has been canceled. And the doSomething method returns null
If we modify the workflow and move the activity execution from the private method into workflow method it works as expected and workflow finishes in canceled status
IhorBerestPaybis
changed the title
[Bug] Generators return null when exception is throws
[Bug] Generators return null when exception is thrown
Nov 25, 2024
Let me point out that you can achieve the desired behavior using the yield from construct:
yield from $this->doSomething()
However, you won't be able to use this to obtain a result from the generator.
I also believe that we should receive an exception in the execution flow if it occurs in the yielded generator. I will discuss with the team whether the current behavior is intended.
What are you really trying to do?
I want to structure workflows in an easy-to-read and understandable manner, especially when the workflow's code is long enough. At my company, we have found that it is easier when we move the part of code that is related to the same action, or part of the flow (activity calls, timers, if statements) into a private function inside the workflow code. Thus we create private methods inside workflow classes that return Generators (simply because of the yield inside that method)
Describe the bug
When an exception is thrown in the generator it returns null instead of throwing that exception in the outer scope, which results in proceeding workflow execution instead of immediate cancel of workflow. See comparison below
Minimal Reproduction
Workflow code
Activity code
By running the example above we get the workflow in completed status, even though the activity has been canceled. And the
doSomething
method returns nullIf we modify the workflow and move the activity execution from the private method into workflow method it works as expected and workflow finishes in canceled status
Environment/Versions
Additional context
No additional context
The text was updated successfully, but these errors were encountered: