Skip to content

Commit 96395be

Browse files
authored
Report sync exceptions to bugsnag (#3789)
1 parent 631a53c commit 96395be

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/SIL.XForge.Scripture/Services/ParatextSyncRunner.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public class ParatextSyncRunner : IParatextSyncRunner
7979
private readonly IDeltaUsxMapper _deltaUsxMapper;
8080
private readonly IParatextNotesMapper _notesMapper;
8181
private readonly ILogger<ParatextSyncRunner> _logger;
82+
private readonly IExceptionHandler _exceptionHandler;
8283
private readonly IGuidService _guidService;
8384
private readonly IHubContext<NotificationHub, INotifier> _hubContext;
8485

@@ -103,6 +104,7 @@ public ParatextSyncRunner(
103104
IParatextNotesMapper notesMapper,
104105
IHubContext<NotificationHub, INotifier> hubContext,
105106
ILogger<ParatextSyncRunner> logger,
107+
IExceptionHandler exceptionHandler,
106108
IGuidService guidService
107109
)
108110
{
@@ -118,6 +120,7 @@ IGuidService guidService
118120
_notesMapper = notesMapper;
119121
_guidService = guidService;
120122
_hubContext = hubContext;
123+
_exceptionHandler = exceptionHandler;
121124
_guidService = guidService;
122125
}
123126

@@ -466,7 +469,8 @@ await UpdateBiblicalTermsAsync(
466469
}
467470
catch (Exception e)
468471
{
469-
if (e is not TaskCanceledException)
472+
// OperationCanceledException is thrown by the MongoDB Driver when a sync is canceled
473+
if (e is not TaskCanceledException and not OperationCanceledException)
470474
{
471475
StringBuilder additionalInformation = new StringBuilder();
472476
foreach (var key in e.Data.Keys)
@@ -479,6 +483,7 @@ await UpdateBiblicalTermsAsync(
479483
_syncMetrics.ErrorDetails = $"{e}{Environment.NewLine}{message}";
480484
_logger.LogError(e, message);
481485
LogMetric(message);
486+
_exceptionHandler.ReportException(e);
482487
}
483488

484489
await CompleteSync(false, canRollbackParatext, token);

test/SIL.XForge.Scripture.Tests/Services/ParatextSyncRunnerTests.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ public async Task SyncAsync_Error()
7373
SFProject project = env.VerifyProjectSync(false);
7474
Assert.That(project.Sync.DataInSync, Is.False);
7575

76-
// Check that the failure was logged in the sync metrics
76+
// Check that the failure was logged in the sync metrics and reported to bugsnag
7777
SyncMetrics syncMetrics = env.GetSyncMetrics("project01");
7878
Assert.That(syncMetrics.Status, Is.EqualTo(SyncStatus.Failed));
79+
env.ExceptionHandler.Received().ReportException(Arg.Any<Exception>());
7980
}
8081

8182
[Test]
@@ -3633,6 +3634,7 @@ public TestEnvironment(bool substituteRealtimeService = false, IDeltaUsxMapper d
36333634
NotesMapper = Substitute.For<IParatextNotesMapper>();
36343635
var hubContext = Substitute.For<IHubContext<NotificationHub, INotifier>>();
36353636
MockLogger = new MockLogger<ParatextSyncRunner>();
3637+
ExceptionHandler = Substitute.For<IExceptionHandler>();
36363638
GuidService = Substitute.For<IGuidService>();
36373639
GuidService.NewObjectId().Returns($"syncuser0{_guidStartNum++}");
36383640

@@ -3648,6 +3650,7 @@ public TestEnvironment(bool substituteRealtimeService = false, IDeltaUsxMapper d
36483650
NotesMapper,
36493651
hubContext,
36503652
MockLogger,
3653+
ExceptionHandler,
36513654
GuidService
36523655
);
36533656
}
@@ -3661,6 +3664,7 @@ public TestEnvironment(bool substituteRealtimeService = false, IDeltaUsxMapper d
36613664
public IRealtimeService SubstituteRealtimeService { get; }
36623665
public IDeltaUsxMapper DeltaUsxMapper { get; }
36633666
public MockLogger<ParatextSyncRunner> MockLogger { get; }
3667+
public IExceptionHandler ExceptionHandler { get; }
36643668
public IGuidService GuidService { get; }
36653669

36663670
/// <summary>

0 commit comments

Comments
 (0)