Skip to content

Commit caaecbe

Browse files
authored
Changed raise to calling Reraise() extension method to preserve the call stack (#230)
1 parent c6e1496 commit caaecbe

File tree

6 files changed

+25
-6
lines changed

6 files changed

+25
-6
lines changed

src/SwaggerProvider.DesignTime/SwaggerProvider.DesignTime.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<Compile Include="..\SwaggerProvider.Runtime\ProvidedApiClientBase.fs">
3333
<Link>ProvidedApiClientBase.fs</Link>
3434
</Compile>
35+
<Compile Include="..\SwaggerProvider.Runtime\Exception.fs" />
3536
<Compile Include="..\SwaggerProvider.Runtime\RuntimeHelpers.fs" />
3637
<Compile Include="..\Common\AssemblyInfo.fs">
3738
<Link>AssemblyInfo.fs</Link>

src/SwaggerProvider.DesignTime/Utils.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ module SchemaReader =
5252

5353
return
5454
if String.IsNullOrEmpty err then
55-
raise wex
55+
wex.Reraise()
5656
else
5757
err.ToString()
5858
| Choice2Of2 e -> return failwith(e.ToString())

src/SwaggerProvider.DesignTime/v2/Parser/Parsers.fs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,7 @@ module Parsers =
361361
else
362362
match Int32.TryParse(property) with
363363
| true, value -> Some value
364-
| false, _ ->
365-
raise
366-
<| UnknownFieldValueException(obj, property, "HTTP Status Code", spec)
364+
| false, _ -> raise(UnknownFieldValueException(obj, property, "HTTP Status Code", spec))
367365

368366
code, parseResponseObject context objValue)
369367

src/SwaggerProvider.DesignTime/v2/Parser/SwaggerParser.fs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ open SwaggerProvider.Internal.v2.Parser.Schema
44
open SwaggerProvider.Internal.v2.Parser.Exceptions
55

66
module internal JsonAdapter =
7+
78
open System.Text.Json
89

910
/// Schema node for Swagger schemes in Json format
@@ -52,9 +53,11 @@ module internal JsonAdapter =
5253
(JsonDocument.Parse string).RootElement |> JsonNodeAdapter
5354

5455
module internal YamlAdapter =
56+
57+
open System
58+
open System.Collections.Generic
5559
open System.IO
5660
open YamlDotNet.Serialization
57-
open System.Collections.Generic
5861

5962
let (|List|_|)(node: obj) =
6063
match node with
@@ -138,7 +141,7 @@ module internal YamlAdapter =
138141
use reader = new StringReader(text)
139142
deserializer.Deserialize(reader) |> YamlNodeAdapter
140143
with
141-
| :? YamlDotNet.Core.YamlException as e when not <| isNull e.InnerException -> raise e.InnerException // inner exceptions are much more informative
144+
| :? YamlDotNet.Core.YamlException as e when not <| isNull e.InnerException -> e.InnerException.Reraise() // inner exceptions are much more informative
142145
| _ -> reraise()
143146

144147
module SwaggerParser =
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[<AutoOpen>]
2+
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
3+
module System.Exception
4+
5+
open System
6+
open System.Diagnostics
7+
open System.Runtime.ExceptionServices
8+
9+
// Useful for reraising exceptions under an async {...} and task {...} contexts
10+
// See this for more details: https://github.com/fsharp/fslang-suggestions/issues/660
11+
type Exception with
12+
13+
[<DebuggerHidden>]
14+
member __.Reraise() =
15+
(ExceptionDispatchInfo.Capture __).Throw()
16+
Unchecked.defaultof<_>

src/SwaggerProvider.Runtime/SwaggerProvider.Runtime.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<Compile Include="..\Common\AssemblyInfo.fs">
2222
<Link>AssemblyInfo.fs</Link>
2323
</Compile>
24+
<Compile Include="Exception.fs" />
2425
<Compile Include="Runtime.fs" />
2526
<Compile Include="ProvidedApiClientBase.fs" />
2627
<Compile Include="RuntimeHelpers.fs" />

0 commit comments

Comments
 (0)