From 4c0a99d24c5d49aa7f400d6b27a2954381994f19 Mon Sep 17 00:00:00 2001 From: GeWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Wed, 15 Apr 2026 08:25:52 +0800 Subject: [PATCH] =?UTF-8?q?fix(coroutine):=20=E4=BC=98=E5=8C=96=E5=8D=8F?= =?UTF-8?q?=E7=A8=8B=E6=89=A9=E5=B1=95=E4=B8=AD=E7=9A=84=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 TaskCanceledException 映射以统一取消状态处理 - 保留原始异常调用栈以避免调试时丢失异常来源 - 优先解包业务异常以避免直接暴露 AggregateException - 使用 ExceptionDispatchInfo.Capture 确保异常栈信息完整 --- .../Coroutine/Extensions/CqrsCoroutineExtensions.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/GFramework.Core/Coroutine/Extensions/CqrsCoroutineExtensions.cs b/GFramework.Core/Coroutine/Extensions/CqrsCoroutineExtensions.cs index b459d7f2..41e54ee2 100644 --- a/GFramework.Core/Coroutine/Extensions/CqrsCoroutineExtensions.cs +++ b/GFramework.Core/Coroutine/Extensions/CqrsCoroutineExtensions.cs @@ -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(); } }