< Summary

Information
Class: IceRpc.Transports.SocketExceptionExtensions
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Transports/SocketExceptionExtensions.cs
Tag: 275_13775359185
Line coverage
84%
Covered lines: 16
Uncovered lines: 3
Coverable lines: 19
Total lines: 37
Line coverage: 84.2%
Branch coverage
80%
Covered branches: 16
Total branches: 20
Branch coverage: 80%
Method coverage
100%
Covered methods: 1
Total methods: 1
Method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ToIceRpcException(...)80%23.742078.94%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Transports/SocketExceptionExtensions.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using System.Net.Sockets;
 4
 5namespace IceRpc.Transports;
 6
 7/// <summary>Provides an extension method for <see cref="SocketException"/> to convert it into an <see
 8/// cref="IceRpcException"/>.</summary>
 9public static class SocketExceptionExtensions
 10{
 11    /// <summary>Converts a <see cref="SocketException"/> into an <see cref="IceRpcException" />.</summary>
 12    /// <param name="exception">The exception to convert.</param>
 13    /// <param name="innerException">The inner exception for the <see cref="IceRpcException"/>, when
 14    /// <see langword="null"/> <paramref name="exception"/> is used as the inner exception.</param>
 15    /// <returns>The <see cref="IceRpcException"/> created from the <see cref="SocketException"/>.</returns>
 16    public static IceRpcException ToIceRpcException(this SocketException exception, Exception? innerException = null)
 7017    {
 7018        innerException ??= exception;
 7019        IceRpcError errorCode = exception.SocketErrorCode switch
 7020        {
 621            SocketError.AddressAlreadyInUse => IceRpcError.AddressInUse,
 022            SocketError.ConnectionAborted => IceRpcError.ConnectionAborted,
 7023            // Shutdown matches EPIPE and ConnectionReset matches ECONNRESET. Both are the result of the peer closing
 7024            // non-gracefully the connection. EPIPE is returned if the socket is closed and the send buffer is empty
 7025            // while ECONNRESET is returned if the send buffer is not empty.
 5326            SocketError.ConnectionReset => IceRpcError.ConnectionAborted,
 227            SocketError.HostUnreachable => IceRpcError.ServerUnreachable,
 028            SocketError.NetworkUnreachable => IceRpcError.ServerUnreachable,
 429            SocketError.Shutdown => IceRpcError.ConnectionAborted,
 430            SocketError.ConnectionRefused => IceRpcError.ConnectionRefused,
 031            SocketError.OperationAborted => IceRpcError.OperationAborted,
 132            _ => IceRpcError.IceRpcError
 7033        };
 34
 7035        return new IceRpcException(errorCode, innerException);
 7036    }
 37}