Skip to content

Commit

Permalink
Merge pull request #1082 from AArnott/fix1081
Browse files Browse the repository at this point in the history
Replace warning with verbose message in log regarding `$/progress` not matching any method
  • Loading branch information
AArnott authored Sep 26, 2024
2 parents 87e4571 + e26cbc5 commit ece3a29
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/StreamJsonRpc/JsonRpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public class JsonRpc : IDisposableObservable, IJsonRpcFormatterCallbacks, IJsonR

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

/// <summary>
/// A singleton error object that can be returned by <see cref="DispatchIncomingRequestAsync(JsonRpcRequest)"/> in error cases
/// for requests that are actually notifications and thus the error will be dropped.
/// </summary>
private static readonly JsonRpcError DroppedError = new();

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly object syncObject = new object();

Expand Down Expand Up @@ -2169,7 +2175,19 @@ private async ValueTask<JsonRpcMessage> DispatchIncomingRequestAsync(JsonRpcRequ
{
if (this.TraceSource.Switch.ShouldTrace(TraceEventType.Warning))
{
this.TraceSource.TraceEvent(TraceEventType.Warning, (int)TraceEvents.RequestWithoutMatchingTarget, "No target methods are registered that match \"{0}\".", request.Method);
if (request.Method == MessageFormatterProgressTracker.ProgressRequestSpecialMethod)
{
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);
}
else
{
this.TraceSource.TraceEvent(TraceEventType.Warning, (int)TraceEvents.RequestWithoutMatchingTarget, "No target methods are registered that match \"{0}\".", request.Method);
}
}

if (!request.IsResponseExpected)
{
return DroppedError;
}

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

if (!request.IsResponseExpected)
{
return DroppedError;
}

JsonRpcError errorMessage = (this.MessageHandler.Formatter as IJsonRpcMessageFactory)?.CreateErrorMessage() ?? new JsonRpcError();
errorMessage.RequestId = request.RequestId;
errorMessage.Error = new JsonRpcError.ErrorDetail
Expand Down

0 comments on commit ece3a29

Please sign in to comment.