Skip to content

Commit

Permalink
1186 json serializer crash server (ionide#1189)
Browse files Browse the repository at this point in the history
* Update LSP library

* Port JsonSerializationException for JsonRpc overrides
  • Loading branch information
TheAngryByrd authored and nojaf committed Nov 3, 2023
1 parent caf26fd commit f8ccf9a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ nuget Expecto.Diff
nuget YoloDev.Expecto.TestSdk
nuget AltCover
nuget GitHubActionsTestLogger
nuget Ionide.LanguageServerProtocol >= 0.4.18
nuget Ionide.LanguageServerProtocol >= 0.4.19
nuget Microsoft.Extensions.Caching.Memory
nuget OpenTelemetry.Api >= 1.3.2
nuget OpenTelemetry.Exporter.OpenTelemetryProtocol >= 1.3.2 # 1.4 bumps to 7.0 versions of System.Diagnostics libs, so can't use it
Expand Down
2 changes: 1 addition & 1 deletion paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ NUGET
System.Collections.Immutable (>= 5.0)
System.Reflection.Metadata (>= 5.0)
Ionide.KeepAChangelog.Tasks (0.1.8) - copy_local: true
Ionide.LanguageServerProtocol (0.4.18)
Ionide.LanguageServerProtocol (0.4.19)
FSharp.Core (>= 6.0)
Newtonsoft.Json (>= 13.0.1)
StreamJsonRpc (>= 2.10.44)
Expand Down
35 changes: 34 additions & 1 deletion src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3098,6 +3098,7 @@ module AdaptiveFSharpLspServer =
| :? LocalRpcException -> Some()
| :? TaskCanceledException -> Some()
| :? OperationCanceledException -> Some()
| :? Newtonsoft.Json.JsonSerializationException -> Some()
| :? System.AggregateException as aex ->
if aex.InnerExceptions.Count = 1 then
(|HandleableException|_|) aex.InnerException
Expand All @@ -3107,11 +3108,43 @@ module AdaptiveFSharpLspServer =

let strategy = StreamJsonRpcTracingStrategy(Tracing.fsacActivitySource)

let (|Flatten|_|) (e: exn) =
match e with
| :? AggregateException as aex ->
let aex = aex.Flatten()

if aex.InnerExceptions.Count = 1 then
Some aex.InnerException
else
Some e
| _ -> Some e

let strategy = StreamJsonRpcTracingStrategy(Tracing.fsacActivitySource)

{ new JsonRpc(handler, ActivityTracingStrategy = strategy) with
member this.IsFatalException(ex: Exception) =
match ex with
| HandleableException -> false
| _ -> true }
| _ -> true

member this.CreateErrorDetails(request: Protocol.JsonRpcRequest, ex: Exception) =
let isSerializable = this.ExceptionStrategy = ExceptionProcessing.ISerializable

match ex with
| Flatten(:? Newtonsoft.Json.JsonSerializationException as ex) ->

let data: obj = if isSerializable then ex else Protocol.CommonErrorData(ex)

Protocol.JsonRpcError.ErrorDetail(
Code = Protocol.JsonRpcErrorCode.ParseError,
Message = ex.Message,
Data = data
)
| _ -> base.CreateErrorDetails(request, ex)

}



let startCore toolsPath workspaceLoaderFactory sourceTextFactory =
use input = Console.OpenStandardInput()
Expand Down

0 comments on commit f8ccf9a

Please sign in to comment.