Skip to content

Commit a191b5f

Browse files
Added additional logging
1 parent 50de8cd commit a191b5f

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

src/JsonRpc/InputHandler.cs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,20 @@ private void HandleRequest(string request)
167167
_scheduler.Add(
168168
type,
169169
item.Request.Method,
170-
async () => {
171-
var result = await _requestRouter.RouteRequest(item.Request);
172-
_outputHandler.Send(result.Value);
170+
async () =>
171+
{
172+
try
173+
{
174+
var result = await _requestRouter.RouteRequest(item.Request);
175+
_outputHandler.Send(result.Value);
176+
}
177+
catch (Exception e)
178+
{
179+
_logger.LogCritical(Events.UnhandledRequest, e, "Unhandled exception executing request {Method}@{Id}", item.Request.Method, item.Request.Id);
180+
// TODO: Should we rethrow or swallow?
181+
// If an exception happens... the whole system could be in a bad state, hence this throwing currently.
182+
throw;
183+
}
173184
}
174185
);
175186
}
@@ -178,8 +189,19 @@ private void HandleRequest(string request)
178189
_scheduler.Add(
179190
type,
180191
item.Notification.Method,
181-
() => {
182-
_requestRouter.RouteNotification(item.Notification);
192+
() =>
193+
{
194+
try
195+
{
196+
_requestRouter.RouteNotification(item.Notification);
197+
}
198+
catch (Exception e)
199+
{
200+
_logger.LogCritical(Events.UnhandledNotification, e, "Unhandled exception executing notification {Method}@{Id}", item.Notification.Method);
201+
// TODO: Should we rethrow or swallow?
202+
// If an exception happens... the whole system could be in a bad state, hence this throwing currently.
203+
throw;
204+
}
183205
return Task.CompletedTask;
184206
}
185207
);

src/JsonRpc/ProcessScheduler.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,16 @@ private void ProcessRequestQueue()
9595
}
9696
catch (Exception e)
9797
{
98-
// TODO: Create proper event ids
99-
_logger.LogCritical(Events.UnhandledRequest, e, "Unhandled exception executing request {Name}", name);
98+
// TODO: Should we rethrow or swallow?
99+
// If an exception happens... the whole system could be in a bad state, hence this throwing currently.
100+
_logger.LogCritical(Events.UnhandledException, e, "Unhandled exception executing request {Name}", name);
101+
throw;
100102
}
101103
}
102104
}
103105
}
104-
catch (OperationCanceledException ex)
106+
catch (OperationCanceledException ex) when (ex.CancellationToken == token)
105107
{
106-
if (ex.CancellationToken != token)
107-
throw;
108108
// OperationCanceledException - The CancellationToken has been canceled.
109109
Task.WaitAll(waitables.ToArray(), TimeSpan.FromMilliseconds(1000));
110110
var keeponrunning = RemoveCompleteTasks(waitables);
@@ -130,6 +130,8 @@ public void Dispose()
130130

131131
static class Events
132132
{
133-
public static EventId UnhandledRequest = new EventId(1337_100);
133+
public static EventId UnhandledException = new EventId(1337_100);
134+
public static EventId UnhandledRequest = new EventId(1337_101);
135+
public static EventId UnhandledNotification = new EventId(1337_102);
134136
}
135137
}

0 commit comments

Comments
 (0)