public bool TryHandleException(ExceptionInformation exceptionInformation, OperationRetrySettings retrySettings, out ExceptionHandlingResult result)
        {
            ServiceEventSource.Current.ReportServiceHealth(_serviceContext, HealthState.Error, "Exception");

            result = new ExceptionHandlingThrowResult();
            return(true);
        }
Ejemplo n.º 2
0
        public XmlDocument XmlOpenFile(string path)
        {
            try
            {
                XmlDocument XmlDoc = new XmlDocument();
                XmlDoc.Load(path);
                return(XmlDoc);
            }
            catch (FileNotFoundException)
            {
                ElmThrowException(13);
                return(null);
            }

            catch (DirectoryNotFoundException)
            {
                ElmThrowException(13);
                return(null);
            }
            catch (XmlException ExceptionInformation)
            {
                ElmThrowException(10, ExceptionInformation.ToString()); // convert the exception information to a string and throw
                return(null);
            }
        }
        public async Task ReportOperationExceptionAsync_PropagatesCalls()
        {
            IServiceRemotingClient client = new Mock <IServiceRemotingClient>().Object;
            ExceptionInformation   exceptionInformation = new ExceptionInformation(new FileNotFoundException());
            OperationRetrySettings retrySettings        = new OperationRetrySettings();
            CancellationToken      cancellationToken    = CancellationToken.None;

            Expression <Func <IServiceRemotingClientFactory, Task <OperationRetryControl> > > expression = f =>
                                                                                                           f.ReportOperationExceptionAsync(
                client,
                exceptionInformation,
                retrySettings,
                cancellationToken);

            OperationRetryControl expectedResult             = new OperationRetryControl();
            Mock <IServiceRemotingClientFactory> factoryMock = new Mock <IServiceRemotingClientFactory>();

            factoryMock.Setup(expression).Returns(Task.FromResult(expectedResult));
            OmexServiceRemotingClientFactory wrapper = new OmexServiceRemotingClientFactory(factoryMock.Object);

            OperationRetryControl actualResult = await wrapper.ReportOperationExceptionAsync(
                client,
                exceptionInformation,
                retrySettings,
                cancellationToken).ConfigureAwait(false);

            factoryMock.Verify(expression, Times.Once);

            Assert.AreEqual(expectedResult, actualResult);
        }
Ejemplo n.º 4
0
        public virtual Task OnResponseHandlerExceptionAsync(IRawConsumer rawConsumer, IConsumerConfiguration cfg, BasicDeliverEventArgs args, Exception exception)
        {
            _logger.LogError($"An unhandled exception was thrown in the response handler for message '{args.BasicProperties.MessageId}'.", exception);
            var innerException = UnwrapInnerException(exception);
            var exceptionInfo  = new ExceptionInformation
            {
                Message       = $"An unhandled exception was thrown when consuming a message\n  MessageId: {args.BasicProperties.MessageId}\n  Queue: '{cfg.Queue.FullQueueName}'\n  Exchange: '{cfg.Exchange.ExchangeName}'\nSee inner exception for more details.",
                ExceptionType = innerException.GetType().FullName,
                StackTrace    = innerException.StackTrace,
                InnerMessage  = innerException.Message
            };

            _logger.LogInformation($"Sending MessageHandlerException with CorrelationId '{args.BasicProperties.CorrelationId}'");
            rawConsumer.Model.BasicPublish(
                exchange: string.Empty,
                routingKey: args.BasicProperties?.ReplyTo ?? string.Empty,
                basicProperties: _propertiesProvider.GetProperties <ExceptionInformation>(p =>
            {
                p.CorrelationId = args.BasicProperties?.CorrelationId ?? string.Empty;
                p.Headers.Add(PropertyHeaders.ExceptionHeader, _messageExceptionName);
            }),
                body: _serializer.Serialize(exceptionInfo)
                );

            if (!cfg.NoAck)
            {
                _logger.LogDebug($"Nack'ing message with delivery tag '{args.DeliveryTag}'.");
                rawConsumer.Model.BasicNack(args.DeliveryTag, false, false);
            }
            return(Task.FromResult(true));
        }
        public bool TryHandleException(ExceptionInformation exceptionInformation, OperationRetrySettings retrySettings, out ExceptionHandlingResult result)
        {
            if (exceptionInformation.Exception is RpcException rpcEx)
            {
                switch (rpcEx.Status.StatusCode)
                {
                case StatusCode.Unavailable when rpcEx.Status.Detail == "Endpoint read failed":
                    Log.LogInformation(exceptionInformation.Exception, "Throwing: {Exception}", exceptionInformation.Exception.Message);
                    result = new ExceptionHandlingThrowResult();
                    return(true);

                case StatusCode.Unavailable:
                case StatusCode.Unknown:
                case StatusCode.Cancelled:
                    Log.LogInformation(exceptionInformation.Exception, "Not transient exception: {Exception}, Retry {@Retry}", exceptionInformation.Exception.Message, retrySettings);
                    result = new ExceptionHandlingRetryResult(exceptionInformation.Exception, false, retrySettings, int.MaxValue);
                    return(true);

                default:
                    Log.LogInformation(exceptionInformation.Exception, "Unknown exception: {Exception}, Retry {@Retry}", exceptionInformation.Exception.Message, retrySettings);
                    result = new ExceptionHandlingThrowResult();
                    return(true);
                }
            }
            else
            {
                Log.LogInformation(exceptionInformation.Exception, "Throwing: {Exception}", exceptionInformation.Exception.Message);
                result = new ExceptionHandlingThrowResult();
                return(true);
            }
        }
Ejemplo n.º 6
0
 public Task <OperationRetryControl> ReportOperationExceptionAsync(IServiceRemotingClient client,
                                                                   ExceptionInformation exceptionInformation,
                                                                   OperationRetrySettings retrySettings,
                                                                   CancellationToken cancellationToken)
 {
     return(serviceRemotingClientFactory.ReportOperationExceptionAsync(((ServiceRemotingClientWrapper)client).Client, exceptionInformation, retrySettings, cancellationToken));
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Method that examines the exception and determines how that exception can be handled.
        /// </summary>
        /// <param name="exceptionInformation">Information about the exception</param>
        /// <param name="retrySettings">The operation retry preferences.</param>
        /// <param name="result">Result of the exception handling</param>
        /// <returns>true if the exception is handled, false otherwise</returns>
        bool IExceptionHandler.TryHandleException(
            ExceptionInformation exceptionInformation,
            OperationRetrySettings retrySettings,
            out ExceptionHandlingResult result)
        {
            var e = exceptionInformation.Exception;

            if (e is ActorConcurrencyLockTimeoutException)
            {
                if (ActorLogicalCallContext.IsPresent())
                {
                    result = new ExceptionHandlingThrowResult()
                    {
                        ExceptionToThrow = e
                    };
                    return(true);
                }

                result = new ExceptionHandlingRetryResult(
                    e,
                    true,
                    retrySettings,
                    retrySettings.DefaultMaxRetryCount);
                return(true);
            }

            result = null;
            return(false);
        }
        /// <summary>
        /// Sends email contains information about error and extra data.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="informationAboutException"></param>
        /// <returns></returns>
        public T Log <T>(ExceptionInformation informationAboutException)
        {
            return(default(T));

            //TODO: Add .NET mailing operations here.
            throw new NotImplementedException();
        }
        public bool TryHandleException(ExceptionInformation exceptionInformation, OperationRetrySettings retrySettings, out ExceptionHandlingResult result)
        {
            this.logger.LogError("retry {RetryAttempt} for {replica}: {exception}", retrySettings.RetryPolicy.TotalNumberOfRetries, exceptionInformation.TargetReplica.ToString(), exceptionInformation.Exception.Message);

            if (IsNotTransient(exceptionInformation))
            {
                this.logger.LogError(exceptionInformation.Exception, "A known non-transient exception occurred on retry {RetryAttempt} for {replica}: {exception}", retrySettings.RetryPolicy.TotalNumberOfRetries, exceptionInformation.TargetReplica.ToString(), exceptionInformation.Exception.Message);
                result = new ExceptionHandlingRetryResult(exceptionInformation.Exception, TransientException.IsNotTransient, TimeSpan.FromSeconds(1), retrySettings.DefaultMaxRetryCountForNonTransientErrors);
                return(true);
            }

            // if exceptionInformation.Exception is known and is transient (can be retried without re-resolving)
            if (IsTransient(exceptionInformation))
            {
                this.logger.LogError(exceptionInformation.Exception, "A known transient exception occurred on retry {RetryAttempt} for {replica}: {exception}", retrySettings.RetryPolicy.TotalNumberOfRetries, exceptionInformation.TargetReplica.ToString(), exceptionInformation.Exception.Message);
                result = new ExceptionHandlingRetryResult(exceptionInformation.Exception, TransientException.IsTransient, TimeSpan.FromSeconds(1), retrySettings.DefaultMaxRetryCountForTransientErrors);
                return(true);
            }


            // if exceptionInformation.Exception is unknown (let the next IExceptionHandler attempt to handle it)
            this.logger.LogError(exceptionInformation.Exception, "A unknown exception occurred on retry {RetryAttempt} for {replica}: {exception}", retrySettings.RetryPolicy.TotalNumberOfRetries, exceptionInformation.TargetReplica.ToString(), exceptionInformation.Exception.Message);
            result = null;
            return(false);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Logs exception with an extra data via email.
        /// </summary>
        /// <typeparam name="T">Type of Id of recorded exception</typeparam>
        /// <param name="informationAboutException">Exception to log.</param>
        public override T Log <T>(ExceptionInformation informationAboutException)
        {
            T id = default(T);

            id = this.ExceptionLogRepository.Log <T>(informationAboutException);
            return(id);
        }
 bool IExceptionHandler.TryHandleException(ExceptionInformation exceptionInformation, OperationRetrySettings retrySettings, out ExceptionHandlingResult result)
 {
     if (exceptionInformation.Exception is FabricNotPrimaryException)
     {
         if (exceptionInformation.TargetReplica == TargetReplicaSelector.Default)
         {
             result = new ExceptionHandlingRetryResult(exceptionInformation.Exception, false, retrySettings, int.MaxValue);
             return(true);
         }
         //ServiceTrace.Source.WriteInfo(ServiceRemotingExceptionHandler.TraceType, "{0} Got exception {1} which does not match the replica target : {2}", (object) this._traceId, (object) exceptionInformation.Exception, (object) exceptionInformation.TargetReplica);
         result = null;
         return(false);
     }
     if (exceptionInformation.Exception is FabricNotReadableException)
     {
         result = new ExceptionHandlingRetryResult(exceptionInformation.Exception, false, retrySettings, int.MaxValue);
         return(true);
     }
     if (exceptionInformation.Exception is FabricTransientException)
     {
         result = new ExceptionHandlingRetryResult(exceptionInformation.Exception, true, retrySettings, int.MaxValue);
         return(true);
     }
     result = null;
     return(false);
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Handles exception and returns action result to take.
        /// </summary>
        /// <param name="ex">Exception</param>
        /// <returns></returns>
        public virtual ExceptionResult Exception(Exception ex)
        {
            ExceptionResult result = null;

            if (ex.IsNotNull())
            {
                ExceptionInformation informationAbouException = new ExceptionInformation(ex);
                if (this.CaterpillarMvcHttpRequest.Browser != null)
                {
                    informationAbouException.ExtraInformation = this.CaterpillarMvcHttpRequest.CaterpillarRequest.ConvertBrowserInformationToDictionary(this.CaterpillarMvcHttpRequest.Browser);
                }
                informationAbouException.ClientIp = this.CaterpillarMvcHttpRequest.GetClientIpAddress();
                if (this.User != null)
                {
                    informationAbouException.UserCultureSettings = this.User.Culture.TwoLetterISOLanguageName;
                    informationAbouException.UserId = this.User.UserId;
                }
                ObjectListCollection objectIds = ApplicationFoundation.Current.ExceptionManager.Log(informationAbouException);
                if (objectIds != null && objectIds.Count > 0)
                {
                    this.ErrorId = objectIds.Where(_id => _id.GetType() == typeof(int) || _id.GetType() == typeof(Guid)).FirstOrDefault();
                }
                this.Error = LanguageStrings.GeneralExceptionMessage;
                result     = new ExceptionResult(ex);
            }

            return(result);
        }
Ejemplo n.º 13
0
        private void Generate(string component, ExceptionInformation exception)
        {
            Dictionary <string, object> param = new Dictionary <string, object>();

            param.Add("name", exception.Label);
            if (exception.Base)
            {
                param.Add("parent", "Exception");
            }
            else
            {
                param.Add("parent", Project.Name + "." + ComponentType.Core.ToString() + "." + Project.Name + "Exception");
            }
            param.Add("namespace", Project.Name + "." + component);

            string output = AppendDirectory(Project.OutputPath, component);

            output = AppendDirectory(output, "Exceptions");
            output = Path.Combine(output, exception.Label + ".cs");

            Aggregator.RegisterFile(component, output);

            string template = GetResource("ExceptionClass.cs");

            Templates.Generate(template, output, param);
        }
 /// <summary>
 /// Handles the exceptions that occur in the CommunicationClient when sending a message to the Service
 /// </summary>
 /// <param name="client">Communication client</param>
 /// <param name="exceptionInformation">Information about exception that happened while communicating with the service.</param>
 /// <param name="retrySettings">Specifies the retry policy that should be used for handling the reported exception.</param>
 /// <param name="cancellationToken">Cancellation token</param>
 /// <returns>
 /// A <see cref="System.Threading.Tasks.Task">Task</see> that represents outstanding operation. The result of the Task is
 /// a <see cref="OperationRetryControl" /> object that provides information on retry policy for this exception.
 /// </returns>
 public Task <OperationRetryControl> ReportOperationExceptionAsync(IServiceRemotingClient client,
                                                                   ExceptionInformation exceptionInformation,
                                                                   OperationRetrySettings retrySettings, CancellationToken cancellationToken)
 {
     return(this.clientFactoryImpl.ReportOperationExceptionAsync((FabricTransportServiceRemotingClient)client,
                                                                 exceptionInformation,
                                                                 retrySettings,
                                                                 cancellationToken));
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Registers the provided <paramref name="exceptionInformation"/> in <see cref="ReportedExceptionInformation"/> and return the registered <see cref="OperationRetryControl"/>. (using <see cref="RegisterOperationRetryControl"/>)
        /// </summary>
        /// <param name="client"></param>
        /// <param name="exceptionInformation"></param>
        /// <param name="retrySettings"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task <OperationRetryControl> ReportOperationExceptionAsync(IServiceRemotingClient client, ExceptionInformation exceptionInformation,
                                                                          OperationRetrySettings retrySettings, CancellationToken cancellationToken)
        {
            _reportedExceptionInformation[client] = exceptionInformation;
            OperationRetryControl operationRetryControl;

            _operationRetryControls.TryGetValue(client, out operationRetryControl);
            return(Task.FromResult(operationRetryControl));
        }
Ejemplo n.º 16
0
 public Task <OperationRetryControl> ReportOperationExceptionAsync(
     IServiceRemotingClient client,
     ExceptionInformation exceptionInformation,
     OperationRetrySettings retrySettings,
     CancellationToken cancellationToken) =>
 m_serviceRemotingClientFactory.ReportOperationExceptionAsync(
     Unwrap(client),
     exceptionInformation,
     retrySettings,
     cancellationToken);
        /// <summary>
        /// Method that examines the exception and determines how that exception can be handled.
        /// </summary>
        /// <param name="exceptionInformation">Information about the exception</param>
        /// <param name="retrySettings">The operation retry preferences.</param>
        /// <param name="result">Result of the exception handling</param>
        /// <returns>true if the exception is handled, false otherwise</returns>
        bool IExceptionHandler.TryHandleException(
            ExceptionInformation exceptionInformation,
            OperationRetrySettings retrySettings,
            out ExceptionHandlingResult result)
        {
            if (exceptionInformation.Exception is FabricNotPrimaryException)
            {
                if (exceptionInformation.TargetReplica == TargetReplicaSelector.PrimaryReplica)
                {
                    result = new ExceptionHandlingRetryResult(
                        exceptionInformation.Exception,
                        false,
                        retrySettings,
                        int.MaxValue);

                    return(true);
                }

                ServiceTrace.Source.WriteInfo(
                    TraceType,
                    "{0} Got exception {1} which does not match the replica target : {2}",
                    this.traceId,
                    exceptionInformation.Exception,
                    exceptionInformation.TargetReplica);

                result = null;
                return(false);
            }

            if (exceptionInformation.Exception is FabricNotReadableException)
            {
                result = new ExceptionHandlingRetryResult(
                    exceptionInformation.Exception,
                    false,
                    retrySettings,
                    int.MaxValue);

                return(true);
            }

            // Note: This code handles retries for FabricTransientException even from Actors, eg. ActorDeletedException.
            if (exceptionInformation.Exception is FabricTransientException)
            {
                result = new ExceptionHandlingRetryResult(
                    exceptionInformation.Exception,
                    true,
                    retrySettings,
                    int.MaxValue);

                return(true);
            }

            result = null;
            return(false);
        }
        bool IExceptionHandler.TryHandleException(ExceptionInformation exceptionInformation, OperationRetrySettings retrySettings, out ExceptionHandlingResult result)
        {
            FabricException exception = exceptionInformation.Exception as FabricException;

            if (exception != null)
            {
                return(TryHandleFabricException(exception, retrySettings, out result));
            }
            result = null;
            return(false);
        }
        /// <summary>
        /// Logs exception with an extra data via async email operation.
        /// </summary>
        /// <typeparam name="T">Type of Id of recorded exception</typeparam>
        /// <param name="informationAboutException">Exception to log.</param>
        public override T Log <T>(ExceptionInformation informationAboutException)
        {
            T id = default(T);

            ThreadPool.QueueUserWorkItem(o =>
            {
                id = this.ExceptionLogRepository.Log <T>(informationAboutException);
            });

            return(id);
        }
        public void when_handling_a_webexception_with_retryable_status_then_a_non_transient_retry_result_that_does_not_resolve_the_address_is_returned(WebExceptionStatus webExceptionStatus)
        {
            // Arrange
            ExceptionHandlingResult exceptionHandlingResult = null;
            var exceptionInformation = new ExceptionInformation(new WebException(string.Empty, webExceptionStatus));

            // Act
            var isKnownException = this.httpExceptionHandler.TryHandleException(exceptionInformation, operationRetrySettings, out exceptionHandlingResult);

            // Assert
            AssertIsTransientRetryResultThatDoesNotResolveTheAddress(exceptionHandlingResult, isKnownException);
        }
        public void when_handling_a_socketexception_then_a_transient_retry_result_that_resolves_the_address_is_returned()
        {
            // Arrange
            ExceptionHandlingResult exceptionHandlingResult = null;
            var exceptionInformation = new ExceptionInformation(new SocketException());

            // Act
            var isKnownException = this.httpExceptionHandler.TryHandleException(exceptionInformation, operationRetrySettings, out exceptionHandlingResult);

            // Assert
            AssertIsTransientRetryResultThatResolvesTheAddress(exceptionHandlingResult, isKnownException);
        }
Ejemplo n.º 22
0
 public static DalExceptionInformation ToDalExceptionInformation(this ExceptionInformation exceptionInformationEntity)
 {
     return(exceptionInformationEntity == null ? null : new DalExceptionInformation
     {
         Id = exceptionInformationEntity.Id,
         ExceptionMessage = exceptionInformationEntity.ExceptionMessage,
         StackTrace = exceptionInformationEntity.StackTrace,
         ActionName = exceptionInformationEntity.ActionName,
         ControllerName = exceptionInformationEntity.ControllerName,
         Date = exceptionInformationEntity.Date
     });
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Handles the exceptions that occur in the CommunicationClient when sending a message to the Service
 /// </summary>
 /// <param name="client">Communication client</param>
 /// <param name="exceptionInformation">Information about exception that happened while communicating with the service.</param>
 /// <param name="retrySettings">Specifies the retry policy that should be used for handling the reported exception.</param>
 /// <param name="cancellationToken">Cancellation token</param>
 /// <returns>
 /// A <see cref="System.Threading.Tasks.Task">Task</see> that represents outstanding operation. The result of the Task is
 /// a <see cref="OperationRetryControl" /> object that provides information on retry policy for this exception.
 /// </returns>
 Task <OperationRetryControl> ICommunicationClientFactory <IServiceRemotingClient> .ReportOperationExceptionAsync(
     IServiceRemotingClient client,
     ExceptionInformation exceptionInformation,
     OperationRetrySettings retrySettings,
     CancellationToken cancellationToken)
 {
     return(this.wcfFactory.ReportOperationExceptionAsync(
                ((WcfServiceRemotingClient)client).WcfClient,
                exceptionInformation,
                retrySettings,
                cancellationToken));
 }
        public void when_handling_a_non_retryable_exception_then_no_retry_result_is_returned()
        {
            // Arrange
            ExceptionHandlingResult exceptionHandlingResult = null;
            var exceptionInformation = new ExceptionInformation(new InvalidOperationException());

            // Act
            var isKnownException = this.httpExceptionHandler.TryHandleException(exceptionInformation, operationRetrySettings, out exceptionHandlingResult);

            // Assert
            Assert.That(isKnownException, Is.False);
            Assert.That(exceptionHandlingResult, Is.Null);
        }
        public void ExceptionHandler_of_ExceptionType_should_not_handle_other_exceptions()
        {
            var exceptionHandler = new ExceptionHandler <ArgumentException>();

            var exceptionInformation   = new ExceptionInformation(new SystemException("A system exception"));
            var operationRetrySettings = new OperationRetrySettings(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(3), 3);
            ExceptionHandlingResult exceptionHandlingResult;

            var canHandle = exceptionHandler.TryHandleException(exceptionInformation, operationRetrySettings, out exceptionHandlingResult);

            canHandle.Should().BeFalse();
            exceptionHandlingResult.Should().BeOfType(typeof(ExceptionHandlingThrowResult));
        }
        public void ExceptionHandler_of_ExceptionType_should_handle_that_exception()
        {
            var exceptionHandler = new ExceptionHandler <ArgumentException>();

            var exceptionInformation   = new ExceptionInformation(new ArgumentException("Some argument error"));
            var operationRetrySettings = new OperationRetrySettings(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(3), 3);
            ExceptionHandlingResult exceptionHandlingResult;

            var canHandle = exceptionHandler.TryHandleException(exceptionInformation, operationRetrySettings, out exceptionHandlingResult);

            canHandle.Should().BeTrue();
            exceptionHandlingResult.Should().BeOfType(typeof(ExceptionHandlingRetryResult));
        }
Ejemplo n.º 27
0
        public Task <OperationRetryControl> ReportOperationExceptionAsync(
            IServiceRemotingClient client,
            ExceptionInformation exceptionInformation,
            OperationRetrySettings retrySettings,
            CancellationToken cancellationToken)
        {
            IServiceRemotingClient innerClient = ((ActivityServiceRemotingClient)client)._inner;

            return(_inner.ReportOperationExceptionAsync(
                       innerClient,
                       exceptionInformation,
                       retrySettings,
                       cancellationToken));
        }
Ejemplo n.º 28
0
        public bool TryHandleException(ExceptionInformation exceptionInformation, OperationRetrySettings retrySettings, out ExceptionHandlingResult result)
        {
            if (exceptionInformation.Exception is TimeoutException)
            {
                result = new ExceptionHandlingRetryResult(exceptionInformation.Exception, false, retrySettings, retrySettings.DefaultMaxRetryCount);
                return(true);
            }
            else if (exceptionInformation.Exception is ProtocolViolationException)
            {
                result = new ExceptionHandlingThrowResult();
                return(true);
            }
            else if (exceptionInformation.Exception is WebException)
            {
                WebException    we            = exceptionInformation.Exception as WebException;
                HttpWebResponse errorResponse = we.Response as HttpWebResponse;

                if (we.Status == WebExceptionStatus.ProtocolError)
                {
                    if (errorResponse.StatusCode == HttpStatusCode.NotFound)
                    {
                        // This could either mean we requested an endpoint that does not exist in the service API (a user error)
                        // or the address that was resolved by fabric client is stale (transient runtime error) in which we should re-resolve.
                        result = new ExceptionHandlingRetryResult(exceptionInformation.Exception, false, retrySettings, retrySettings.DefaultMaxRetryCount);
                        return(true);
                    }

                    if (errorResponse.StatusCode == HttpStatusCode.InternalServerError)
                    {
                        // The address is correct, but the server processing failed.
                        // Retry the operation without re-resolving the address.
                        result = new ExceptionHandlingRetryResult(exceptionInformation.Exception, true, retrySettings, retrySettings.DefaultMaxRetryCount);
                        return(true);
                    }
                }

                if (we.Status == WebExceptionStatus.Timeout ||
                    we.Status == WebExceptionStatus.RequestCanceled ||
                    we.Status == WebExceptionStatus.ConnectionClosed ||
                    we.Status == WebExceptionStatus.ConnectFailure)
                {
                    result = new ExceptionHandlingRetryResult(exceptionInformation.Exception, false, retrySettings, retrySettings.DefaultMaxRetryCount);
                    return(true);
                }
            }

            result = null;
            return(false);
        }
Ejemplo n.º 29
0
        public bool TryHandleException(ExceptionInformation exceptionInformation, OperationRetrySettings retrySettings, out ExceptionHandlingResult result)
        {
            if (exceptionInformation.Exception is TimeoutException)
            {
                result = new ExceptionHandlingRetryResult(exceptionInformation.Exception, false, retrySettings, retrySettings.DefaultMaxRetryCount);
                return true;
            }
            else if (exceptionInformation.Exception is ProtocolViolationException)
            {
                result = new ExceptionHandlingThrowResult();
                return true;
            }
            else if (exceptionInformation.Exception is WebException)
            {
                WebException we = exceptionInformation.Exception as WebException;
                HttpWebResponse errorResponse = we.Response as HttpWebResponse;

                if (we.Status == WebExceptionStatus.ProtocolError)
                {
                    if (errorResponse.StatusCode == HttpStatusCode.NotFound)
                    {
                        // This could either mean we requested an endpoint that does not exist in the service API (a user error)
                        // or the address that was resolved by fabric client is stale (transient runtime error) in which we should re-resolve.
                        result = new ExceptionHandlingRetryResult(exceptionInformation.Exception, false, retrySettings, retrySettings.DefaultMaxRetryCount);
                        return true;
                    }

                    if (errorResponse.StatusCode == HttpStatusCode.InternalServerError)
                    {
                        // The address is correct, but the server processing failed.
                        // Retry the operation without re-resolving the address.
                        result = new ExceptionHandlingRetryResult(exceptionInformation.Exception, true, retrySettings, retrySettings.DefaultMaxRetryCount);
                        return true;
                    }
                }

                if (we.Status == WebExceptionStatus.Timeout ||
                    we.Status == WebExceptionStatus.RequestCanceled ||
                    we.Status == WebExceptionStatus.ConnectionClosed ||
                    we.Status == WebExceptionStatus.ConnectFailure)
                {
                    result = new ExceptionHandlingRetryResult(exceptionInformation.Exception, false, retrySettings, retrySettings.DefaultMaxRetryCount);
                    return true;
                }
            }

            result = null;
            return false;
        }
 public Task <OperationRetryControl> ReportOperationExceptionAsync(
     IServiceRemotingClient client,
     ExceptionInformation exceptionInformation,
     OperationRetrySettings retrySettings,
     CancellationToken cancellationToken)
 {
     return(_InnerClientFactory.ReportOperationExceptionAsync(
                // This expects a an object of type FabricTransportServiceRemotingClient, hence
                // why we need to expose the InnerClient here.
                // https://github.com/Azure/service-fabric-services-and-actors-dotnet/issues/43
                ((TrackingFabricTransportServiceRemotingClient)client).InnerClient,
                exceptionInformation,
                retrySettings,
                cancellationToken));
 }
        public Task <OperationRetryControl> ReportOperationExceptionAsync(
            IServiceRemotingClient client,
            ExceptionInformation exceptionInformation,
            OperationRetrySettings retrySettings,
            CancellationToken cancellationToken)
        {
            var customClient = client as CustomServiceRemotingClient;

            if (customClient != null)
            {
                client = customClient.Wrapped;
            }

            return(this._wrapped.ReportOperationExceptionAsync(client, exceptionInformation, retrySettings, cancellationToken));
        }
        public bool TryHandleException(ExceptionInformation exceptionInformation, OperationRetrySettings retrySettings, out ExceptionHandlingResult result)
        {
            if (exceptionInformation == null)
            {
                throw new ArgumentNullException(nameof(exceptionInformation));
            }

            if (retrySettings == null)
            {
                throw new ArgumentNullException(nameof(retrySettings));
            }

            result = new ExceptionHandlingRetryResult(exceptionInformation.Exception, false, retrySettings, retrySettings.DefaultMaxRetryCount);

            return true;
        }
Ejemplo n.º 33
0
        private void Generate(string component, ExceptionInformation exception)
        {
            Dictionary<string, object> param = new Dictionary<string, object>();

            param.Add("name", exception.Label);
            if (exception.Base) {
                param.Add("parent", "Exception");
            } else {
                param.Add("parent", Project.Name + "." + ComponentType.Core.ToString() + "." + Project.Name + "Exception");
            }
            param.Add("namespace", Project.Name + "." + component);

            string output = AppendDirectory(Project.OutputPath, component);
            output = AppendDirectory(output, "Exceptions");
            output = Path.Combine(output, exception.Label + ".cs");

            Aggregator.RegisterFile(component, output);

            string template = GetResource("ExceptionClass.cs");
            Templates.Generate(template, output, param);
        }
Ejemplo n.º 34
0
		private void AddExceptionInformation(bool addIPCheck)
		{
			ValueWrapper currentException = DebugEventHandler.Instance.EventObjects.Thread.GetCurrentException();

			if (currentException != null && !currentException.IsNull())
			{
				ValueWrapper dereferencedException = currentException.DereferenceValue();

				if (dereferencedException != null)
				{
					ClassWrapper currentExceptionClass = dereferencedException.GetClassInformation();
					ModuleWrapper module = currentExceptionClass.GetModule();
					ExceptionInformation exceptionInformation = new ExceptionInformation(module.GetName(), currentExceptionClass.GetToken());
					uint throwingMethodToken = 0;
					uint currentIP = 0;

					if (addIPCheck && DebugEventHandler.Instance.EventObjects.Thread != null)
					{
						FrameWrapper activeFrame = DebugEventHandler.Instance.EventObjects.Thread.GetActiveFrame();

						if (activeFrame != null && activeFrame.IsILFrame())
						{
							bool exactLocation = false;
							currentIP = activeFrame.GetIP(ref exactLocation);
							exceptionInformation.IP = currentIP;

							throwingMethodToken = activeFrame.GetFunctionToken();
							exceptionInformation.ThrowingMethodToken = throwingMethodToken;
						}
					}

					int indexOfExisting = 0;

					if (addIPCheck)
					{
						indexOfExisting = Project.Instance.FindExceptionInformationByIP(exceptionInformation);
					}
					else
					{
						indexOfExisting = Project.Instance.Exceptions.IndexOf(exceptionInformation);
					}

					if (indexOfExisting >= 0)
					{
						ExceptionInformation existingExceptionInformation = Project.Instance.Exceptions[indexOfExisting];
						existingExceptionInformation.Skip = true;
						Project.Instance.IsSaved = false;

						if (addIPCheck)
						{
							existingExceptionInformation.ThrowingMethodToken = throwingMethodToken;
							existingExceptionInformation.IP = currentIP;
						}
					}
					else
					{
						Project.Instance.Exceptions.Add(exceptionInformation);
						Project.Instance.IsSaved = false;
					}
				}
			}
		}
Ejemplo n.º 35
0
 /// <summary>
     /// Erstellt eine neue Instanz der Klasse mit einem ExceptionInfo-Objekt.
 /// </summary>
     /// <param name="exInfo">Ein ExceptionInfo-Objekt, mit Informationen über den aufgetretenen Fehler.</param>
 public ErrorWindow(ExceptionInformation exInfo) : this()
 {
   _exceptionInfo = exInfo;
 }
        public bool TryHandleException(ExceptionInformation exceptionInformation, OperationRetrySettings retrySettings, out ExceptionHandlingResult result)
        {
            Exception e = exceptionInformation.Exception;

            Logger.Debug("OnHandleException {0}", e);

            if (e is TimeoutException)
            {
                result = new ExceptionHandlingRetryResult(e, false, retrySettings, retrySettings.DefaultMaxRetryCount);
                return true;
            }

            if (e is ProtocolViolationException)
            {
                result = new ExceptionHandlingRetryResult(e, false, retrySettings, retrySettings.DefaultMaxRetryCount);
                return true;
            }

            if (e is HttpRequestException)
            {
                HttpRequestException he = (HttpRequestException) e;

                // this should not happen, but let's do a sanity check
                if (null == he.InnerException)
                {
                    result = new ExceptionHandlingRetryResult(e, false, retrySettings, retrySettings.DefaultMaxRetryCount);
                    return true;
                }

                e = he.InnerException;
            }

            if (e is WebException)
            {
                WebException we = (WebException) e;
                HttpWebResponse errorResponse = we.Response as HttpWebResponse;

                if (we.Status == WebExceptionStatus.ProtocolError)
                {
                    if (errorResponse.StatusCode == HttpStatusCode.NotFound)
                    {
                        // This could either mean we requested an endpoint that does not exist in the service API (a user error)
                        // or the address that was resolved by fabric client is stale (transient runtime error) in which we should re-resolve.
                        result = new ExceptionHandlingRetryResult(e, false, retrySettings, retrySettings.DefaultMaxRetryCount);
                        return true;
                    }

                    if (errorResponse.StatusCode == HttpStatusCode.InternalServerError)
                    {
                        // The address is correct, but the server processing failed.
                        // This could be due to conflicts when writing the word to the dictionary.
                        // Retry the operation without re-resolving the address.
                        result = new ExceptionHandlingRetryResult(e, true, retrySettings, retrySettings.DefaultMaxRetryCount);
                        return true;
                    }
                }

                if (we.Status == WebExceptionStatus.Timeout ||
                    we.Status == WebExceptionStatus.RequestCanceled ||
                    we.Status == WebExceptionStatus.ConnectionClosed ||
                    we.Status == WebExceptionStatus.ConnectFailure)
                {
                    result = new ExceptionHandlingRetryResult(e, false, retrySettings, retrySettings.DefaultMaxRetryCount);
                    return true;
                }
            }

            result = new ExceptionHandlingRetryResult(e, false, retrySettings, retrySettings.DefaultMaxRetryCount);
            return true;
        }
        public bool TryHandleException(ExceptionInformation exceptionInformation, OperationRetrySettings retrySettings, out ExceptionHandlingResult result)
        {
            if (exceptionInformation == null)
            {
                throw new ArgumentNullException(nameof(exceptionInformation));
            }

            var ex = exceptionInformation.Exception;

            // errors where we didn't get a response from the service.

            if (ex is TaskCanceledException || ex is TimeoutException)
            {
                _logger.RetryingServiceCall(ex.GetType().Name);

                return CreateExceptionHandlingRetryResult(false, ex, out result);
            }

            if (ex is ProtocolViolationException)
            {
                _logger.RetryingServiceCall("ProtocolViolationException", null, ex);

                return CreateExceptionHandlingRetryResult(false, ex, out result);
            }

            var webEx = ex as WebException ?? ex.InnerException as WebException;
            if (webEx != null)
            {
                if (webEx.Status == WebExceptionStatus.Timeout ||
                    webEx.Status == WebExceptionStatus.RequestCanceled ||
                    webEx.Status == WebExceptionStatus.ConnectionClosed ||
                    webEx.Status == WebExceptionStatus.ConnectFailure)
                {
                    _logger.RetryingServiceCall("WebExceptionStatus " + webEx.Status, null, ex);

                    return CreateExceptionHandlingRetryResult(false, webEx, out result);
                }
            }

            // we got a response from the service - let's try to get the StatusCode to see if we should retry.

            if (_options.RetryHttpStatusCodeErrors)
            {
                HttpStatusCode? httpStatusCode = null;
                HttpWebResponse webResponse = null;
                HttpResponseMessage responseMessage = null;

                var httpEx = ex as HttpResponseException;
                if (httpEx != null)
                {
                    responseMessage = httpEx.Response;
                    httpStatusCode = httpEx.Response.StatusCode;
                }
                else if (webEx != null)
                {
                    webResponse = webEx.Response as HttpWebResponse;
                    httpStatusCode = webResponse?.StatusCode;
                }

                if (httpStatusCode.HasValue)
                {
                    if (httpStatusCode == HttpStatusCode.NotFound)
                    {
                        // This could either mean we requested an endpoint that does not exist in the service API (a user error)
                        // or the address that was resolved by fabric client is stale (transient runtime error) in which we should re-resolve.

                        _logger.RetryingServiceCall("HTTP 404");

                        result = new ExceptionHandlingRetryResult(
                            exceptionId: "HTTP 404",
                            isTransient: false,
                            retryDelay: TimeSpan.FromMilliseconds(100),
                            maxRetryCount: 2);

                        return true;
                    }

                    if ((int)httpStatusCode >= 500 && (int)httpStatusCode < 600)
                    {
                        // The address is correct, but the server processing failed.
                        // Retry the operation without re-resolving the address.

                        // we want to log the response in case it contains useful information (e.g. in dev environments)
                        string errorResponse = null;
                        if (webResponse != null)
                        {
                            using (StreamReader streamReader = new StreamReader(webResponse.GetResponseStream()))
                            {
                                errorResponse = streamReader.ReadToEnd();
                            }
                        }
                        else if (responseMessage != null)
                        {
                            // not sure if just calling ReadAsStringAsync().Result can result in a deadlock.
                            // so better safe than sorry...
                            // http://stackoverflow.com/questions/22628087/calling-async-method-synchronously
                            // AsyncEx library would be good but I don't want to take a dependency on that just for this one case.
                            errorResponse = Task.Run(() => responseMessage.Content.ReadAsStringAsync()).Result;
                        }

                        _logger.RetryingServiceCall($"HTTP {(int) httpStatusCode}", errorResponse);

                        return CreateExceptionHandlingRetryResult(true, ex, out result);
                    }
                }
            }

            _logger.ServiceCallFailed(ex);

            result = null;
            return false;
        }
 internal static extern bool MiniDumpWriteDump(IntPtr processHandle, int processId, SafeHandle fileHandle, DumpType dumpType, ref ExceptionInformation exception, IntPtr userStream, IntPtr callback);