Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1186 json serializer crash server #1189

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion paket.dependencies
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
Expand Up @@ -130,7 +130,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
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