From 865d9941ffea8d3015851d2c5575198e726e80f6 Mon Sep 17 00:00:00 2001 From: Vlad Zarytovskii Date: Mon, 22 Jan 2024 15:44:32 +0100 Subject: [PATCH 1/3] Preserve original stacktrace in state machines if available --- src/FSharp.Core/resumable.fs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/FSharp.Core/resumable.fs b/src/FSharp.Core/resumable.fs index e63e79f92dd..2af7c88f5ec 100644 --- a/src/FSharp.Core/resumable.fs +++ b/src/FSharp.Core/resumable.fs @@ -115,6 +115,7 @@ module StateMachineHelpers = "__stateMachine should always be guarded by __useResumableCode and only used in valid state machine implementations" module ResumableCode = + open System.Runtime.ExceptionServices let inline GetResumptionFunc (sm: byref>) = sm.ResumptionDynamicInfo.ResumptionFunc @@ -294,7 +295,10 @@ module ResumableCode = // reraise at the end of the finally block match savedExn with | None -> true - | Some exn -> raise exn + | Some exn -> + // This should preserve initial location for the failure (file + line, given they're available). + ExceptionDispatchInfo.Capture(exn).Throw() + true else let rf = GetResumptionFunc &sm @@ -384,7 +388,8 @@ module ResumableCode = if __stack_fin then match savedExn with | None -> () - | Some exn -> raise exn + | Some exn -> + ExceptionDispatchInfo.Capture(exn).Throw() __stack_fin //-- RESUMABLE CODE END From 663f1be89d3044d4c221109d870ec191c1f46042 Mon Sep 17 00:00:00 2001 From: Vlad Zarytovskii Date: Mon, 22 Jan 2024 15:55:51 +0100 Subject: [PATCH 2/3] Update release notes --- docs/release-notes/.FSharp.Core/8.0.300.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 docs/release-notes/.FSharp.Core/8.0.300.md diff --git a/docs/release-notes/.FSharp.Core/8.0.300.md b/docs/release-notes/.FSharp.Core/8.0.300.md new file mode 100644 index 00000000000..9acf7d07635 --- /dev/null +++ b/docs/release-notes/.FSharp.Core/8.0.300.md @@ -0,0 +1,3 @@ +### Fixed + +* Preserve original stack traces in resumable state machines generated code if available. ([PR #16568](https://github.com/dotnet/fsharp/pull/16568)) \ No newline at end of file From 9123e7fb542c765cf3869da9a3f466750a5c3b2f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 22 Jan 2024 16:10:25 +0000 Subject: [PATCH 3/3] Automated command ran: fantomas Co-authored-by: vzarytovskii <1260985+vzarytovskii@users.noreply.github.com> --- src/FSharp.Core/resumable.fs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/FSharp.Core/resumable.fs b/src/FSharp.Core/resumable.fs index 2af7c88f5ec..24131ea155f 100644 --- a/src/FSharp.Core/resumable.fs +++ b/src/FSharp.Core/resumable.fs @@ -388,8 +388,7 @@ module ResumableCode = if __stack_fin then match savedExn with | None -> () - | Some exn -> - ExceptionDispatchInfo.Capture(exn).Throw() + | Some exn -> ExceptionDispatchInfo.Capture(exn).Throw() __stack_fin //-- RESUMABLE CODE END