Skip to content

Commit f50f8e8

Browse files
Preserve original stacktrace in state machines if available (#16568)
* Preserve original stacktrace in state machines if available * Update release notes * Automated command ran: fantomas Co-authored-by: vzarytovskii <1260985+vzarytovskii@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 904b641 commit f50f8e8

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Fixed
2+
3+
* Preserve original stack traces in resumable state machines generated code if available. ([PR #16568](https://github.com/dotnet/fsharp/pull/16568))

src/FSharp.Core/resumable.fs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ module StateMachineHelpers =
115115
"__stateMachine should always be guarded by __useResumableCode and only used in valid state machine implementations"
116116

117117
module ResumableCode =
118+
open System.Runtime.ExceptionServices
118119

119120
let inline GetResumptionFunc (sm: byref<ResumableStateMachine<'Data>>) =
120121
sm.ResumptionDynamicInfo.ResumptionFunc
@@ -294,7 +295,10 @@ module ResumableCode =
294295
// reraise at the end of the finally block
295296
match savedExn with
296297
| None -> true
297-
| Some exn -> raise exn
298+
| Some exn ->
299+
// This should preserve initial location for the failure (file + line, given they're available).
300+
ExceptionDispatchInfo.Capture(exn).Throw()
301+
true
298302
else
299303
let rf = GetResumptionFunc &sm
300304

@@ -384,7 +388,7 @@ module ResumableCode =
384388
if __stack_fin then
385389
match savedExn with
386390
| None -> ()
387-
| Some exn -> raise exn
391+
| Some exn -> ExceptionDispatchInfo.Capture(exn).Throw()
388392

389393
__stack_fin
390394
//-- RESUMABLE CODE END

0 commit comments

Comments
 (0)