Skip to content

Commit ece3a29

Browse files
authored
Merge pull request #1082 from AArnott/fix1081
Replace warning with verbose message in log regarding `$/progress` not matching any method
2 parents 87e4571 + e26cbc5 commit ece3a29

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/StreamJsonRpc/JsonRpc.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ public class JsonRpc : IDisposableObservable, IJsonRpcFormatterCallbacks, IJsonR
3131

3232
private static readonly MethodInfo MarshalWithControlledLifetimeOpenGenericMethodInfo = typeof(JsonRpc).GetMethods(BindingFlags.Static | BindingFlags.NonPublic).Single(m => m.Name == nameof(MarshalWithControlledLifetime) && m.IsGenericMethod);
3333

34+
/// <summary>
35+
/// A singleton error object that can be returned by <see cref="DispatchIncomingRequestAsync(JsonRpcRequest)"/> in error cases
36+
/// for requests that are actually notifications and thus the error will be dropped.
37+
/// </summary>
38+
private static readonly JsonRpcError DroppedError = new();
39+
3440
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
3541
private readonly object syncObject = new object();
3642

@@ -2169,7 +2175,19 @@ private async ValueTask<JsonRpcMessage> DispatchIncomingRequestAsync(JsonRpcRequ
21692175
{
21702176
if (this.TraceSource.Switch.ShouldTrace(TraceEventType.Warning))
21712177
{
2172-
this.TraceSource.TraceEvent(TraceEventType.Warning, (int)TraceEvents.RequestWithoutMatchingTarget, "No target methods are registered that match \"{0}\".", request.Method);
2178+
if (request.Method == MessageFormatterProgressTracker.ProgressRequestSpecialMethod)
2179+
{
2180+
this.TraceSource.TraceEvent(TraceEventType.Verbose, (int)TraceEvents.RequestWithoutMatchingTarget, "No target methods are registered that match \"{0}\". This is expected since the formatter is expected to have intercepted this special method and dispatched to a local IProgress<T> object.", request.Method);
2181+
}
2182+
else
2183+
{
2184+
this.TraceSource.TraceEvent(TraceEventType.Warning, (int)TraceEvents.RequestWithoutMatchingTarget, "No target methods are registered that match \"{0}\".", request.Method);
2185+
}
2186+
}
2187+
2188+
if (!request.IsResponseExpected)
2189+
{
2190+
return DroppedError;
21732191
}
21742192

21752193
JsonRpcError errorMessage = (this.MessageHandler.Formatter as IJsonRpcMessageFactory)?.CreateErrorMessage() ?? new JsonRpcError();
@@ -2188,6 +2206,11 @@ private async ValueTask<JsonRpcMessage> DispatchIncomingRequestAsync(JsonRpcRequ
21882206
this.TraceSource.TraceEvent(TraceEventType.Warning, (int)TraceEvents.RequestWithoutMatchingTarget, "Invocation of \"{0}\" cannot occur because arguments do not match any registered target methods.", request.Method);
21892207
}
21902208

2209+
if (!request.IsResponseExpected)
2210+
{
2211+
return DroppedError;
2212+
}
2213+
21912214
JsonRpcError errorMessage = (this.MessageHandler.Formatter as IJsonRpcMessageFactory)?.CreateErrorMessage() ?? new JsonRpcError();
21922215
errorMessage.RequestId = request.RequestId;
21932216
errorMessage.Error = new JsonRpcError.ErrorDetail

0 commit comments

Comments
 (0)