From 3415be4c56deb348de274c5555bd93ad54a43903 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sat, 20 May 2017 11:29:20 -0400 Subject: [PATCH] handle some crash cases --- src/Android/AutofillService.cs | 4 ++-- src/App/Repositories/LoginRepository.cs | 4 ++-- src/App/Services/SyncService.cs | 10 ++++++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Android/AutofillService.cs b/src/Android/AutofillService.cs index dc5ad1227..96d942792 100644 --- a/src/Android/AutofillService.cs +++ b/src/Android/AutofillService.cs @@ -122,8 +122,8 @@ namespace Bit.Android root.Dispose(); e.Dispose(); } - // Some unknown condition is causing NullReferenceException's in production. Suppress it for now. - catch(NullReferenceException) { } + // Suppress exceptions so that service doesn't crash + catch { } } public override void OnInterrupt() diff --git a/src/App/Repositories/LoginRepository.cs b/src/App/Repositories/LoginRepository.cs index 45657df45..1e462803f 100644 --- a/src/App/Repositories/LoginRepository.cs +++ b/src/App/Repositories/LoginRepository.cs @@ -15,13 +15,13 @@ namespace Bit.App.Repositories public Task> GetAllByUserIdAsync(string userId) { - var logins = Connection.Table().Where(f => f.UserId == userId).Cast(); + var logins = Connection.Table().Where(l => l.UserId == userId).Cast(); return Task.FromResult(logins); } public Task> GetAllByUserIdAsync(string userId, bool favorite) { - var logins = Connection.Table().Where(f => f.UserId == userId && f.Favorite == favorite) + var logins = Connection.Table().Where(l => l.UserId == userId && l.Favorite == favorite) .Cast(); return Task.FromResult(logins); } diff --git a/src/App/Services/SyncService.cs b/src/App/Services/SyncService.cs index 215779418..bdd2bfdce 100644 --- a/src/App/Services/SyncService.cs +++ b/src/App/Services/SyncService.cs @@ -304,7 +304,10 @@ namespace Bit.App.Services return; } - var localFolders = (await _folderRepository.GetAllByUserIdAsync(_authService.UserId).ConfigureAwait(false)) + var localFolders = (await _folderRepository.GetAllByUserIdAsync(_authService.UserId) + .ConfigureAwait(false)) + .GroupBy(f => f.Id) + .Select(f => f.First()) .ToDictionary(f => f.Id); foreach(var serverFolder in serverFolders) @@ -339,7 +342,10 @@ namespace Bit.App.Services return; } - var localLogins = (await _loginRepository.GetAllByUserIdAsync(_authService.UserId).ConfigureAwait(false)) + var localLogins = (await _loginRepository.GetAllByUserIdAsync(_authService.UserId) + .ConfigureAwait(false)) + .GroupBy(s => s.Id) + .Select(s => s.First()) .ToDictionary(s => s.Id); foreach(var serverLogin in serverLogins)