mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-07 00:39:00 +08:00
fix(coroutine): 优化协程扩展中的异常处理机制
- 添加 TaskCanceledException 映射以统一取消状态处理 - 保留原始异常调用栈以避免调试时丢失异常来源 - 优先解包业务异常以避免直接暴露 AggregateException - 使用 ExceptionDispatchInfo.Capture 确保异常栈信息完整
This commit is contained in:
parent
96ffd49b31
commit
4c0a99d24c
@ -45,6 +45,7 @@ public static class CqrsCoroutineExtensions
|
||||
|
||||
if (task.IsCanceled)
|
||||
{
|
||||
// 取消态与成功态区分:协程层统一映射为 TaskCanceledException。
|
||||
var canceledException = new TaskCanceledException(task);
|
||||
if (onError != null)
|
||||
{
|
||||
@ -52,16 +53,18 @@ public static class CqrsCoroutineExtensions
|
||||
yield break;
|
||||
}
|
||||
|
||||
// 保留原始抛出栈,避免调试时丢失异常来源。
|
||||
ExceptionDispatchInfo.Capture(canceledException).Throw();
|
||||
}
|
||||
|
||||
if (!task.IsFaulted)
|
||||
yield break;
|
||||
|
||||
// 优先解包业务异常,避免直接暴露 AggregateException。
|
||||
var exception = task.Exception!.InnerException ?? task.Exception;
|
||||
if (onError != null)
|
||||
onError.Invoke(exception);
|
||||
else
|
||||
// 继续保留原始栈信息。
|
||||
ExceptionDispatchInfo.Capture(exception).Throw();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user