< Summary

Class:Azure.Messaging.EventHubs.Amqp.ExceptionExtensions
Assembly:Azure.Messaging.EventHubs
File(s):C:\Git\azure-sdk-for-net\sdk\eventhub\Azure.Messaging.EventHubs\src\Amqp\ExceptionExtensions.cs
Covered lines:15
Uncovered lines:1
Coverable lines:16
Total lines:81
Line coverage:93.7% (15 of 16)
Covered branches:17
Total branches:18
Branch coverage:94.4% (17 of 18)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
TranslateServiceException(...)-90%90%
TranslateConnectionCloseDuringLinkCreationException(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\eventhub\Azure.Messaging.EventHubs\src\Amqp\ExceptionExtensions.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Threading.Tasks;
 6using Azure.Core;
 7using Microsoft.Azure.Amqp;
 8
 9namespace Azure.Messaging.EventHubs.Amqp
 10{
 11    /// <summary>
 12    ///   The set of extension methods for the <see cref="Exception" /> class.
 13    /// </summary>
 14    ///
 15    internal static class ExceptionExtensions
 16    {
 17        /// <summary>
 18        ///   Considers an exception surfaced during an AMQP-based service operation, unwrapping
 19        ///   and translating it into the form that should be considered for error handling
 20        ///   decisions.
 21        /// </summary>
 22        ///
 23        /// <param name="instance">The instance that this method was invoked on.</param>
 24        /// <param name="eventHubName">The name of the Event Hub that the service operation was targeting.</param>
 25        ///
 26        /// <returns>The <see cref="Exception" /> that corresponds to the <paramref name="instance" /> and which represe
 27        ///
 28        public static Exception TranslateServiceException(this Exception instance,
 29                                                          string eventHubName)
 30        {
 22631            Argument.AssertNotNull(instance, nameof(instance));
 32
 22433            switch (instance)
 34            {
 35                case AmqpException amqpEx:
 036                    return AmqpError.CreateExceptionForError(amqpEx.Error, eventHubName);
 37
 9438                case OperationCanceledException operationEx when (operationEx.InnerException is AmqpException):
 1239                    return AmqpError.CreateExceptionForError(((AmqpException)operationEx.InnerException).Error, eventHub
 40
 8241                case OperationCanceledException operationEx when (operationEx.InnerException != null):
 1642                    return operationEx.InnerException;
 43
 6644                case OperationCanceledException operationEx when (!(operationEx is TaskCanceledException)):
 6245                    return new EventHubsException(eventHubName, operationEx.Message, EventHubsException.FailureReason.Se
 46
 47                default:
 13448                    return instance;
 49            }
 50        }
 51
 52        /// <summary>
 53        ///   Considers an exception surfaced during the creation of an AMQP link, determining if the cause was a race c
 54        ///   with the connection closing and translating it into the form that should be considered for error handling 
 55        /// </summary>
 56        ///
 57        /// <param name="instance">The instance that this method was invoked on.</param>
 58        /// <param name="eventHubName">The name of the Event Hub that the service operation was targeting.</param>
 59        ///
 60        /// <returns>The <see cref="Exception" /> that corresponds to the <paramref name="instance" /> and which represe
 61        ///
 62        public static Exception TranslateConnectionCloseDuringLinkCreationException(this Exception instance,
 63                                                                                    string eventHubName)
 64        {
 5265            Argument.AssertNotNull(instance, nameof(instance));
 66
 5067            switch (instance)
 68            {
 1469                case InvalidOperationException _ when (instance.Message.IndexOf("when the connection is closing", String
 70                case TaskCanceledException _:
 471                    return new EventHubsException(true, eventHubName, Resources.CouldNotCreateLink, EventHubsException.F
 72
 73                case ObjectDisposedException _:
 274                    return new EventHubsException(false, eventHubName, Resources.CouldNotCreateLink, EventHubsException.
 75
 76                default:
 4477                    return instance;
 78            }
 79        }
 80    }
 81}