Skip to content

Commit

Permalink
catch any exception raised during file classification
Browse files Browse the repository at this point in the history
  • Loading branch information
rkm committed Sep 28, 2023
1 parent 75ab213 commit 6d12e4d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ protected override void ProcessMessageImpl(IMessageHeader header, ExtractedFileS
{
failures = _classifier.Classify(toProcess);
}
catch (ArithmeticException ae)
catch (Exception e)
{
SendVerificationMessage(statusMessage, header, tag, VerifiedFileStatus.ErrorWontRetry, $"Exception while classifying {statusMessage.GetType().Name}:\n{ae}");
SendVerificationMessage(statusMessage, header, tag, VerifiedFileStatus.ErrorWontRetry, $"Exception while classifying {statusMessage.GetType().Name}:\n{e}. File could not be scanned.");
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using IsIdentifiable.Failures;
using IsIdentifiable.Failures;
using IsIdentifiable.Reporting;
using Microservices.IsIdentifiable.Service;
using Moq;
Expand Down Expand Up @@ -290,29 +290,6 @@ 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<IClassifier>(MockBehavior.Strict);
mockClassifier.Setup(x => x.Classify(It.IsAny<IFileInfo>())).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);
}

#endregion
}
}

0 comments on commit 6d12e4d

Please sign in to comment.