Report argument deserialization failures more precisely #402
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Instead of responding with a general exception that claims the client didn't send an argument for a given parameter, we now report that an argument deserialization failed, and include all inner exception details.
BEFORE
AFTER
In addition to the improved message, the
RemoteMethodNotFoundExceptiontype now contains extra data with all the type, message and callstack info for all inner exceptions similar to how it would if the exception had been thrown from the RPC server method itself. The full JSON-RPC error message sent to the client and accessible through this exception is:{ "jsonrpc": "2.0", "id": 2, "error": { "code": -32602, "message": "Unable to find method 'MethodWithArgThatFailsToDeserialize/1' on {no object} for the following reasons: Deserializing JSON-RPC argument with name \"arg1\" and position 0 to type \"JsonRpcTests+TypeThrowsWhenDeserialized\" failed: This exception is meant to be thrown.", "data": { "type": "System.AggregateException", "message": "One or more errors occurred.", "stack": null, "code": -2146233088, "inner": { "type": "StreamJsonRpc.RpcArgumentDeserializationException", "message": "Deserializing JSON-RPC argument with name \"arg1\" and position 0 to type \"JsonRpcTests+TypeThrowsWhenDeserialized\" failed: This exception is meant to be thrown.", "stack": " at StreamJsonRpc.JsonMessageFormatter.JsonRpcRequest.TryGetArgumentByNameOrIndex(String name, Int32 position, Type typeHint, Object& value) in D:\\git\\streamjsonrpc\\src\\StreamJsonRpc\\JsonMessageFormatter.cs:line 748\r\n at StreamJsonRpc.Protocol.JsonRpcRequest.TryGetTypedArguments(ReadOnlySpan`1 parameters, Span`1 typedArguments) in D:\\git\\streamjsonrpc\\src\\StreamJsonRpc\\Protocol\\JsonRpcRequest.cs:line 166\r\n at StreamJsonRpc.JsonMessageFormatter.JsonRpcRequest.TryGetTypedArguments(ReadOnlySpan`1 parameters, Span`1 typedArguments) in D:\\git\\streamjsonrpc\\src\\StreamJsonRpc\\JsonMessageFormatter.cs:line 717\r\n at StreamJsonRpc.TargetMethod.TryGetArguments(JsonRpcRequest request, MethodSignature method, Span`1 arguments) in D:\\git\\streamjsonrpc\\src\\StreamJsonRpc\\Reflection\\TargetMethod.cs:line 156\r\n at StreamJsonRpc.TargetMethod..ctor(JsonRpcRequest request, List`1 candidateMethodTargets) in D:\\git\\streamjsonrpc\\src\\StreamJsonRpc\\Reflection\\TargetMethod.cs:line 48", "code": -2146233088, "inner": { "type": "System.Exception", "message": "This exception is meant to be thrown.", "stack": " at JsonRpcJsonHeadersTests.TypeThrowsWhenDeserializedConverter.ReadJson(JsonReader reader, Type objectType, TypeThrowsWhenDeserialized existingValue, Boolean hasExistingValue, JsonSerializer serializer) in D:\\git\\streamjsonrpc\\src\\StreamJsonRpc.Tests\\JsonRpcJsonHeadersTests.cs:line 243\r\n at Newtonsoft.Json.JsonConverter`1.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)\r\n at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)\r\n at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType, JsonSerializer jsonSerializer)\r\n at StreamJsonRpc.JsonMessageFormatter.JsonRpcRequest.TryGetArgumentByNameOrIndex(String name, Int32 position, Type typeHint, Object& value) in D:\\git\\streamjsonrpc\\src\\StreamJsonRpc\\JsonMessageFormatter.cs:line 732", "code": -2146233088, "inner": null } } } } }When there are multiple overloads and all of them fail, an exception for each overload that failed will be included so the investigation can consider why each overload was a mismatch.
When one overload fails but another overload succeeds, the succeeding overload is invoked as before. But even in that case, we now trace a warning message regarding the conversion failure as it occurs.
Fixes #400