Skip to content

Commit

Permalink
(#147) TestUtils.Exceptions: remove Option from the return type
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Oct 31, 2021
1 parent 56079de commit 86c86b6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Emulsion.Tests/Database/DatabaseStructureTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ let ``Unique constraint should hold``(): unit =
let! ex = Async.AwaitTask(Assert.ThrowsAnyAsync(fun() ->
upcast Async.StartAsTask(DataStorage.transaction settings addNewContent)
))
let sqlEx = Exceptions.unwrap<SqliteException> ex |> Option.get
let sqlEx = Exceptions.unwrap<SqliteException> ex
Assert.Contains("UNIQUE constraint failed", sqlEx.Message)
})
4 changes: 2 additions & 2 deletions Emulsion.Tests/TestUtils/Exceptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
open System
open Microsoft.EntityFrameworkCore

let rec unwrap<'a when 'a :> Exception>(ex: Exception): 'a option =
let rec unwrap<'a when 'a :> Exception>(ex: Exception): 'a =
match ex with
| :? 'a as ex -> Some ex
| :? 'a as ex -> ex
| :? AggregateException as ax when ax.InnerExceptions.Count = 1 -> unwrap(Seq.exactlyOne ax.InnerExceptions)
| :? DbUpdateException as dx when not(isNull dx.InnerException) -> unwrap dx.InnerException
| _ -> failwithf $"Unable to unwrap the following exception into {typeof<'a>.FullName}:\n{ex}"

0 comments on commit 86c86b6

Please sign in to comment.