Skip to content

Commit 35fa2a9

Browse files
authored
Include internal error in Result.get (#433)
1 parent 1370528 commit 35fa2a9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/FSharpPlus/Extensions/Result.fs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,13 @@ module Result =
6868
with e -> Error e
6969

7070
/// Gets the 'Ok' value. If it's an 'Error' this function will throw an exception.
71-
let get (source: Result<'T,'Error>) = match source with Ok x -> x | _ -> invalidArg "source" "Result value was Error"
71+
let get (source: Result<'T,'Error>) =
72+
match source with
73+
| Ok x -> x
74+
| Error e ->
75+
match box e with
76+
| :? exn as e -> raise <| System.ArgumentException ("Result value was Error", "source", e)
77+
| e -> invalidArg "source" ("Result value was Error: " + string e)
7278

7379
/// Extracts the Ok value or use the supplied default value when it's an Error.
7480
let defaultValue (value:'T) (source: Result<'T,'Error>) : 'T = match source with Ok v -> v | _ -> value

0 commit comments

Comments
 (0)