< Summary - Combined Code Coverage

Information
Class: NLightning.Daemon.Services.Ipc.IpcRequestRouter
Assembly: NLightning.Daemon
File(s): /home/runner/work/NLightning/NLightning/src/NLightning.Daemon/Services/Ipc/IpcRouting.cs
Tag: 57_24045730253
Line coverage
0%
Covered lines: 0
Uncovered lines: 20
Coverable lines: 20
Total lines: 54
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
RouteAsync()0%620%
Error(...)100%210%

File(s)

/home/runner/work/NLightning/NLightning/src/NLightning.Daemon/Services/Ipc/IpcRouting.cs

#LineLine coverage
 1using MessagePack;
 2using Microsoft.Extensions.Logging;
 3
 4namespace NLightning.Daemon.Services.Ipc;
 5
 6using Daemon.Ipc.Interfaces;
 7using Domain.Client.Enums;
 8using Transport.Ipc;
 9
 10/// <summary>
 11/// Default router that uses a map of handlers keyed by command.
 12/// </summary>
 13internal sealed class IpcRequestRouter : IIpcRequestRouter
 14{
 15    private readonly IReadOnlyDictionary<ClientCommand, IIpcCommandHandler> _handlers;
 16    private readonly ILogger<IpcRequestRouter> _logger;
 17
 018    public IpcRequestRouter(IEnumerable<IIpcCommandHandler> handlers, ILogger<IpcRequestRouter> logger)
 19    {
 020        _handlers = handlers.ToDictionary(h => h.Command);
 021        _logger = logger;
 022    }
 23
 24    public async Task<IpcEnvelope> RouteAsync(IpcEnvelope request, CancellationToken ct)
 25    {
 026        if (!_handlers.TryGetValue(request.Command, out var handler))
 27        {
 028            return Error(request, "unknown_command", $"Unknown command: {request.Command}");
 29        }
 30
 31        try
 32        {
 033            return await handler.HandleAsync(request, ct);
 34        }
 035        catch (Exception ex)
 36        {
 037            _logger.LogError(ex, "IPC handler error for {Command}", request.Command);
 038            return Error(request, "server_error", ex.Message);
 39        }
 040    }
 41
 42    private static IpcEnvelope Error(IpcEnvelope request, string code, string message)
 43    {
 044        var payload = MessagePackSerializer.Serialize(new IpcError { Code = code, Message = message });
 045        return new IpcEnvelope
 046        {
 047            Version = request.Version,
 048            Command = request.Command,
 049            CorrelationId = request.CorrelationId,
 050            Kind = IpcEnvelopeKind.Error,
 051            Payload = payload
 052        };
 53    }
 54}