Skip to content

Preserve original stacktrace in state machines if available #16568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/release-notes/.FSharp.Core/8.0.300.md
Original file line number Diff line number Diff line change
@@ -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))
8 changes: 6 additions & 2 deletions src/FSharp.Core/resumable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResumableStateMachine<'Data>>) =
sm.ResumptionDynamicInfo.ResumptionFunc
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -384,7 +388,7 @@ 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
Expand Down