Skip to content

Commit

Permalink
Preserve original stacktrace in state machines if available (dotnet#1…
Browse files Browse the repository at this point in the history
…6568)

* Preserve original stacktrace in state machines if available

* Update release notes

* Automated command ran: fantomas

  Co-authored-by: vzarytovskii <[email protected]>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
vzarytovskii and github-actions[bot] authored Jan 23, 2024
1 parent 904b641 commit f50f8e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
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

0 comments on commit f50f8e8

Please sign in to comment.