-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Context Stop still executing next step #55
Comments
Extra info: the return of the stopped step is empty, it should be an Ok() in this case. |
Hi @VictorTBX, do you think it's a bug in stop() or inside the auditTrail? |
I've tried to reproduce with a POC and the problem didn't happen. I'll need to take more info from the source project in which the bug is occurring. const { usecase, Ok, step } = require("@herbsjs/herbs")
const useCaseTest = () =>
usecase("Test Stop", {
setup: (ctx) => (ctx.di = Object.assign({}, {}, {})),
"Step1": step(async (ctx) => {
try {
console.log("entered step1")
await new Promise(r => setTimeout(r, 2000));
if(true) {
ctx.ret = "step1"
ctx.stop()
}
} catch (error) {
console.log("error")
}
return Ok()
}),
"Step2": step(async (ctx) => {
console.log("entered step2")
ctx.ret = "step2"
return Ok()
})
})
const execute = async () => {
const usecase = useCaseTest()
await usecase.run()
console.log(usecase.auditTrail)
}
execute() |
@VictorTBX ok, let me know if you need some help into this |
@VictorTBX take a look at this test implemented with |
I am having difficulties to reproduce this error. The same problem occurred in another usecase. But it's "random", I can't find a pattern. I was thinking it could be due to some misusage of async, but the implementation on buchu simply iterate through the steps and then do a "break" when the stop is true, so it shouldn't be the problem. @BritoDoug different it is because the steps have more complex implementations, but the flow is the same. |
Describe the bug
When I use the .stop() function of context, according to the audit, the code still executed the next step.
To Reproduce
Add two steps to an usecase
In the first step use ctx.stop() and return Ok() followed by it
In the second step add anything and return Ok() as well
Log the usecase auditTrail
Check that the second step was executed and both steps have the property "stopped":true
Expected behavior
When ctx.stop() is called, the next step should not be executed and the usecase should finish.
Audit Trail Json Example
The text was updated successfully, but these errors were encountered: