Skip to content

Commit 7412b8d

Browse files
thomhurstclaude
andauthored
fix: Simplify SubModule exception handling control flow (#1563) (#1701)
- Return result directly instead of going through TaskCompletionSource - Throw exception directly instead of re-awaiting the TCS - Use TrySetResult/TrySetException for safety - Clearer control flow and proper exception propagation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 3702144 commit 7412b8d

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/ModularPipelines/Modules/SubModule.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,21 @@ public async Task<T> Execute(Func<Task<T>> action)
2626
Duration = stopwatch.Elapsed;
2727
EndTime = DateTimeOffset.UtcNow;
2828
Status = Status.Successful;
29-
SubModuleResultTaskCompletionSource.SetResult(result);
29+
SubModuleResultTaskCompletionSource.TrySetResult(result);
30+
31+
return result;
3032
}
3133
catch (Exception ex)
3234
{
3335
Duration = stopwatch.Elapsed;
3436
EndTime = DateTimeOffset.UtcNow;
3537
Status = Status.Failed;
36-
SubModuleResultTaskCompletionSource.SetException(new SubModuleFailedException(this, ex));
37-
}
3838

39-
return await SubModuleResultTaskCompletionSource.Task.ConfigureAwait(false);
39+
var wrappedException = new SubModuleFailedException(this, ex);
40+
SubModuleResultTaskCompletionSource.TrySetException(wrappedException);
41+
42+
throw wrappedException;
43+
}
4044
}
4145

4246
public override Task CallbackTask => SubModuleResultTaskCompletionSource.Task;

0 commit comments

Comments
 (0)