Skip to content

Commit 00fcbc2

Browse files
Jimmy ByrdTheAngryByrd
authored andcommitted
better stack traces for asyncresult
1 parent 6ae5cfa commit 00fcbc2

File tree

6 files changed

+53
-11
lines changed

6 files changed

+53
-11
lines changed

src/FsToolkit.ErrorHandling/Async.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ namespace FsToolkit.ErrorHandling
33
[<RequireQualifiedAccess>]
44
module Async =
55

6-
let singleton value = value |> async.Return
6+
let inline singleton value = value |> async.Return
77

8-
let bind f x = async.Bind(x, f)
8+
let inline bind f x = async.Bind(x, f)
99

1010
let apply f x =
1111
bind (fun f' ->
1212
bind (fun x' -> singleton(f' x')) x) f
1313

14-
let map f x = x |> bind (f >> singleton)
14+
let inline map f x = x |> bind (f >> singleton)
1515

1616
let map2 f x y =
1717
(apply (apply (singleton f) x) y)

src/FsToolkit.ErrorHandling/AsyncResult.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ open System.Threading.Tasks
55
[<RequireQualifiedAccess>]
66
module AsyncResult =
77

8-
let map f ar =
8+
let inline map f ar =
99
Async.map (Result.map f) ar
1010

1111
let mapError f ar =

src/FsToolkit.ErrorHandling/AsyncResultCE.fs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module AsyncResultCE =
2323
Async.AwaitTask taskResult
2424
#endif
2525

26-
member __.ReturnFrom
26+
member inline __.ReturnFrom
2727
(result: Result<'T, 'TError>)
2828
: Async<Result<'T, 'TError>> =
2929
async.Return result
@@ -38,7 +38,7 @@ module AsyncResultCE =
3838
member __.Zero () : Async<Result<unit, 'TError>> =
3939
async.Return <| result.Zero ()
4040

41-
member __.Bind
41+
member inline __.Bind
4242
(asyncResult: Async<Result<'T, 'TError>>,
4343
binder: 'T -> Async<Result<'U, 'TError>>)
4444
: Async<Result<'U, 'TError>> =
@@ -57,7 +57,7 @@ module AsyncResultCE =
5757
this.Bind(Async.AwaitTask taskResult, binder)
5858
#endif
5959

60-
member this.Bind
60+
member inline this.Bind
6161
(result: Result<'T, 'TError>, binder: 'T -> Async<Result<'U, 'TError>>)
6262
: Async<Result<'U, 'TError>> =
6363
this.Bind(this.ReturnFrom result, binder)
@@ -109,7 +109,7 @@ module AsyncResultCE =
109109
this.While(enum.MoveNext,
110110
this.Delay(fun () -> binder enum.Current)))
111111

112-
member __.BindReturn(x: Async<Result<'T,'U>>, f) = AsyncResult.map f x
112+
member inline __.BindReturn(x: Async<Result<'T,'U>>, f) = AsyncResult.map f x
113113
member __.BindReturn(x: Async<Choice<'T,'U>>, f) = __.BindReturn(x |> Async.map Result.ofChoice, f)
114114
member __.BindReturn(x: Result<'T,'U>, f) = __.BindReturn(x |> Async.singleton, f)
115115
member __.BindReturn(x: Choice<'T,'U>, f) = __.BindReturn(x |> Result.ofChoice |> Async.singleton, f)
@@ -173,7 +173,7 @@ module AsyncResultCEExtensions =
173173
#endif
174174

175175

176-
member __.BindReturn(x: Async<'T>, f) =
176+
member inline __.BindReturn(x: Async<'T>, f) =
177177
__.BindReturn(x |> Async.map Result.Ok, f)
178178

179179
#if !FABLE_COMPILER

src/FsToolkit.ErrorHandling/ResultCE.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module ResultCE =
1515
member this.Zero () : Result<unit, 'TError> =
1616
this.Return ()
1717

18-
member __.Bind
18+
member inline __.Bind
1919
(result: Result<'T, 'TError>, binder: 'T -> Result<'U, 'TError>)
2020
: Result<'U, 'TError> =
2121
Result.bind binder result
@@ -25,7 +25,7 @@ module ResultCE =
2525
: unit -> Result<'T, 'TError> =
2626
generator
2727

28-
member __.Run
28+
member inline __.Run
2929
(generator: unit -> Result<'T, 'TError>)
3030
: Result<'T, 'TError> =
3131
generator ()

tests/FsToolkit.ErrorHandling.Tests/AsyncResultCE.fs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,27 @@ let ``AsyncResultCE applicative tests`` =
418418

419419

420420

421+
let failureFunc () = async {
422+
return failwith "I'm a failure"
423+
}
424+
425+
let iDoCalls () = asyncResult {
426+
let! int1 = Ok 1
427+
let! int2 = Ok 2
428+
do! failureFunc ()
429+
}
430+
431+
432+
433+
434+
let ``AsyncResultCE stack traces`` =
435+
testList "AsyncResultCE Stack traces" [
436+
testCaseAsync "Stacktrace1" <| async {
437+
let! result = iDoCalls ()
438+
Expect.isError result ""
439+
}
440+
]
441+
421442
let allTests = testList "AsyncResultCETests" [
422443
``AsyncResultCE return Tests``
423444
``AsyncResultCE return! Tests``
@@ -427,4 +448,5 @@ let allTests = testList "AsyncResultCETests" [
427448
``AsyncResultCE using Tests``
428449
``AsyncResultCE loop Tests``
429450
``AsyncResultCE applicative tests``
451+
``AsyncResultCE stack traces``
430452
]

tests/FsToolkit.ErrorHandling.Tests/ResultCE.fs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,25 @@ let ``ResultCE applicative tests`` =
277277
Expect.equal actual (Error errorMsg1) "Should be Error"
278278
]
279279

280+
281+
let failureFunc () =
282+
failwith "I'm a failure"
283+
284+
285+
let iDoCalls () = result {
286+
let! int1 = Ok 1
287+
let! int2 = Ok 2
288+
do! failureFunc ()
289+
}
290+
291+
292+
let ``ResultCE stack traces`` =
293+
ftestList "ResultCE Stack traces" [
294+
testCase "Stacktrace1" <| fun () ->
295+
let result = iDoCalls ()
296+
Expect.isError result ""
297+
]
298+
280299
let allTests = testList "Result CE Tests" [
281300
``ResultCE return Tests``
282301
``ResultCE return! Tests``
@@ -286,4 +305,5 @@ let allTests = testList "Result CE Tests" [
286305
``ResultCE using Tests``
287306
``ResultCE loop Tests``
288307
``ResultCE applicative tests``
308+
``ResultCE stack traces``
289309
]

0 commit comments

Comments
 (0)