diff --git a/src/microservices/Microservices.IsIdentifiable/Service/IsIdentifiableQueueConsumer.cs b/src/microservices/Microservices.IsIdentifiable/Service/IsIdentifiableQueueConsumer.cs index 9eae37958..997ccbf9a 100644 --- a/src/microservices/Microservices.IsIdentifiable/Service/IsIdentifiableQueueConsumer.cs +++ b/src/microservices/Microservices.IsIdentifiable/Service/IsIdentifiableQueueConsumer.cs @@ -65,8 +65,13 @@ protected override void ProcessMessageImpl(IMessageHeader header, ExtractedFileS } catch (Exception e) { - SendVerificationMessage(statusMessage, header, tag, VerifiedFileStatus.ErrorWontRetry, $"Exception while classifying {statusMessage.GetType().Name}:\n{e}. File could not be scanned."); - return; + if (e is ArithmeticException) + { + SendVerificationMessage(statusMessage, header, tag, VerifiedFileStatus.ErrorWontRetry, $"Exception while classifying {statusMessage.GetType().Name}:\n{e}"); + return; + } + + throw; } foreach (Failure f in failures) diff --git a/tests/microservices/Microservices.IsIdentifiable.Tests/Service/IsIdentifiableQueueConsumerTests.cs b/tests/microservices/Microservices.IsIdentifiable.Tests/Service/IsIdentifiableQueueConsumerTests.cs index 6040ddf64..caa304a5d 100644 --- a/tests/microservices/Microservices.IsIdentifiable.Tests/Service/IsIdentifiableQueueConsumerTests.cs +++ b/tests/microservices/Microservices.IsIdentifiable.Tests/Service/IsIdentifiableQueueConsumerTests.cs @@ -1,4 +1,4 @@ -using IsIdentifiable.Failures; +using IsIdentifiable.Failures; using IsIdentifiable.Reporting; using Microservices.IsIdentifiable.Service; using Moq; @@ -252,6 +252,52 @@ public void ProcessMessage_ClassifierArithmeticException_SendsErrorWontRetry() Assert.True(_response.Report.StartsWith("Exception while classifying ExtractedFileStatusMessage:\nSystem.ArithmeticException: divide by zero")); } + [Test] + public void ProcessMessage_ClassifierUnhandledException_CallsFatal() + { + // Arrange + + var mockClassifier = new Mock(MockBehavior.Strict); + mockClassifier.Setup(x => x.Classify(It.IsAny())).Throws(new Exception("whee")); + + var consumer = GetNewIsIdentifiableQueueConsumer(null, mockClassifier.Object); + + // Act + + consumer.TestMessage(_extractedFileStatusMessage); + + // Assert + + TestTimelineAwaiter.Await(() => _fatalArgs != null, "Expected Fatal to be called"); + Assert.AreEqual("ProcessMessageImpl threw unhandled exception", _fatalArgs?.Message); + Assert.AreEqual("whee", _fatalArgs?.Exception?.Message); + Assert.AreEqual(0, consumer.NackCount); + Assert.AreEqual(0, consumer.AckCount); + } + + [Test] + public void ProcessMessage_ClassifierInvalidFile_CallsFatal() + { + // Arrange + + var mockClassifier = new Mock(MockBehavior.Strict); + mockClassifier.Setup(x => x.Classify(It.IsAny())).Throws(new ApplicationException("File does not contain valid preamble and header")); + + var consumer = GetNewIsIdentifiableQueueConsumer(null, mockClassifier.Object); + + // Act + + consumer.TestMessage(_extractedFileStatusMessage); + + // Assert + + TestTimelineAwaiter.Await(() => _fatalArgs != null, "Expected Fatal to be called"); + Assert.AreEqual("ProcessMessageImpl threw unhandled exception", _fatalArgs?.Message); + Assert.AreEqual("File does not contain valid preamble and header", _fatalArgs?.Exception?.Message); + Assert.AreEqual(0, consumer.NackCount); + Assert.AreEqual(0, consumer.AckCount); + } + #endregion } }