Skip to content

Commit

Permalink
Replace warning with verbose message in log regarding $/progress no…
Browse files Browse the repository at this point in the history
…t matching any method

Also skip construction of an error response to notifications that will never receive it.
  • Loading branch information
AArnott committed Sep 26, 2024
1 parent 87e4571 commit e26cbc5
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 e26cbc5

Please sign in to comment.