diff --git a/agent/nanobot/nanobot_test.go b/agent/nanobot/nanobot_test.go index 9ffe03d..5507aa0 100644 --- a/agent/nanobot/nanobot_test.go +++ b/agent/nanobot/nanobot_test.go @@ -395,8 +395,8 @@ func TestArrWithTask(t *testing.T) { it.True(errors.Is(err, errArr)), it.Equal(len(chalk.tasks), 1), it.Equal(chalk.tasks[0], "arr-step"), - it.Equal(chalk.dones, 1), - it.Equal(len(chalk.failed), 0), + it.Equal(chalk.dones, 0), + it.Equal(len(chalk.failed), 1), it.Equal(chalk.subs, 1), ) }) diff --git a/agent/nanobot/runtime.go b/agent/nanobot/runtime.go index 160982a..0bb3f78 100644 --- a/agent/nanobot/runtime.go +++ b/agent/nanobot/runtime.go @@ -200,14 +200,19 @@ func (f Arr[S]) WithTaskf(taskf func(S) string, donef ...func(S) string) Arr[S] } c.Task(ctx, taskf(s)) - defer func() { - if len(donef) > 0 && donef[0] != nil { - c.Done(donef[0](s)) - } else { - c.Done() - } - }() - return f(c.Sub(ctx), s, opt...) + val, err := f(c.Sub(ctx), s, opt...) + if err != nil { + c.Fail(err) + return val, err + } + + if len(donef) > 0 && donef[0] != nil { + c.Done(donef[0](s)) + } else { + c.Done() + } + + return val, err } }