Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
handle bad datastore errors by resetting
Browse files Browse the repository at this point in the history
  • Loading branch information
sashei committed Jun 10, 2019
1 parent dd6234e commit a6cf858
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 56 deletions.
25 changes: 3 additions & 22 deletions Lockbox.xcodeproj/project.pbxproj
Expand Up @@ -177,6 +177,7 @@
7D5F1D8120866D8200688DEA /* Differentiator.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7DEA1C4120362E09008AD7C4 /* Differentiator.framework */; };
7D6FB87B204F00E2005E23AA /* StatusAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6FB87A204F00E2005E23AA /* StatusAlert.swift */; };
7D788F0520AA3B5D00976D79 /* SpinnerAlert.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7D1D2F0720AA39700011BFC8 /* SpinnerAlert.xib */; };
7D79A5CD22A6FE130094D189 /* AccountAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AA5492DA3988625D1DAB5BD /* AccountAction.swift */; };
7D8057EC2135E51300D41BDD /* CredentialProviderStoreSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D8057EB2135E51300D41BDD /* CredentialProviderStoreSpec.swift */; };
7D8057EE2135ED8F00D41BDD /* ASCredentialIdentityStore+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D8057ED2135ED8F00D41BDD /* ASCredentialIdentityStore+.swift */; };
7D8057EF2135ED8F00D41BDD /* ASCredentialIdentityStore+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D8057ED2135ED8F00D41BDD /* ASCredentialIdentityStore+.swift */; };
Expand Down Expand Up @@ -248,10 +249,9 @@
7DFF2EF4213857E100F001ED /* CredentialProviderPresenterSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DFF2EF3213857E100F001ED /* CredentialProviderPresenterSpec.swift */; };
9BFB48C59623367F328FE265 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = BCAF40329CC78C0CBF5E632C /* Localizable.strings */; };
A1B04DCCB276B7FD665F1C96 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 135D40AD8E5C6CC264F33683 /* InfoPlist.strings */; };
D4AC7F5522980EEC00F75ACF /* SnapshotsXCUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4AC7F5422980EEC00F75ACF /* SnapshotsXCUITests.swift */; };
D5BCA68D229DA4A800CF980C /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = D5BCA68B229DA4A800CF980C /* InfoPlist.strings */; };
D5BCA694229DA4E000CF980C /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = D5BCA692229DA4E000CF980C /* Localizable.strings */; };
D4AC7F5522980EEC00F75ACF /* SnapshotsXCUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4AC7F5422980EEC00F75ACF /* SnapshotsXCUITests.swift */; };
D59BC9902296EA5A009BA380 /* ItemList.strings in Resources */ = {isa = PBXBuildFile; fileRef = D59BC98E2296EA5A009BA380 /* ItemList.strings */; };
D5CC9BB8207D13660013CDEC /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D5CC9BB7207D13660013CDEC /* LaunchScreen.storyboard */; };
D5E2930A207D59050039A0AC /* FiraSans-Bold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = D5E29308207D59030039A0AC /* FiraSans-Bold.ttf */; };
D5E2930B207D59050039A0AC /* FiraSans-Italic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = D5E29309207D59040039A0AC /* FiraSans-Italic.ttf */; };
Expand Down Expand Up @@ -570,27 +570,7 @@
80C24E078F9DA15264F2FA6F /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Localizable.strings; sourceTree = "<group>"; };
B0E84623AB91A6A141DD8403 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/InfoPlist.strings; sourceTree = "<group>"; };
B3554B229BDD46895D14A661 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/InfoPlist.strings; sourceTree = "<group>"; };
7E904CA28EBB7443F9FE89AC /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/OnboardingConfirmation.strings; sourceTree = "<group>"; };
869D4637A6FA14D4794329EB /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/AccountSetting.strings; sourceTree = "<group>"; };
8EE9491EA5AC961DB7C1DC0F /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/AutofillOnboarding.strings; sourceTree = "<group>"; };
93F14299868926282C7BE457 /* it */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/SetupAutofill.strings; sourceTree = "<group>"; };
946A4B9DA79F205FE9FDF7E2 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/SettingList.strings; sourceTree = "<group>"; };
9B1743909D27F5ADDCFB9070 /* it */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/CredentialWelcome.strings; sourceTree = "<group>"; };
A1E846EF8E1A41B85537A2B8 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/SettingList.strings; sourceTree = "<group>"; };
A39E4C8BAFEFCF421BB0CCA1 /* it */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/AccountSetting.strings; sourceTree = "<group>"; };
A5B1408487E377D6B6A45776 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/SettingList.strings; sourceTree = "<group>"; };
A6BC453496C837E6DC2EB35B /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/OnboardingConfirmation.strings; sourceTree = "<group>"; };
B9274E1988CF7A31906531EB /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/Welcome.strings; sourceTree = "<group>"; };
BBDA4B1E97EFFAB3638EE76B /* it */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/SettingList.strings; sourceTree = "<group>"; };
BCCD42ABBCCE5AD2EBAA24A8 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/ItemDetail.strings; sourceTree = "<group>"; };
BDA64A5480E65531D1760676 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/CredentialWelcome.strings; sourceTree = "<group>"; };
C3814B9B885EB543F5E69DE6 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Welcome.strings; sourceTree = "<group>"; };
C39D4CB984C16D5E2BD2C503 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Welcome.strings; sourceTree = "<group>"; };
C4E546209CFC87F20E83D345 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Welcome.strings; sourceTree = "<group>"; };
CE6E429AA6C7438EDF6473FA /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/AccountSetting.strings; sourceTree = "<group>"; };
D0A64422B480D23AD53FEBB0 /* it */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/Welcome.strings; sourceTree = "<group>"; };
D4AC7F5422980EEC00F75ACF /* SnapshotsXCUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnapshotsXCUITests.swift; sourceTree = "<group>"; };
D50920EA22849F6600AC9580 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Welcome.strings; sourceTree = "<group>"; };
D50920F62284A18100AC9580 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/ItemList.strings; sourceTree = "<group>"; };
D578C36E229F099D00E08CFF /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/SetupAutofill.strings; sourceTree = "<group>"; };
D578C370229F09B600E08CFF /* it */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/SetupAutofill.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1857,6 +1837,7 @@
7DB9DEA32140D04700239D31 /* ItemListDisplayAction.swift in Sources */,
7DB9DEA42140D41E00239D31 /* UIFont+.swift in Sources */,
7D80F30B2118DCC700DA191B /* CredentialProviderView.swift in Sources */,
7D79A5CD22A6FE130094D189 /* AccountAction.swift in Sources */,
D80D41C321FD6D48008A7B11 /* CredentialItemDetailStore.swift in Sources */,
7D09B2492125DD6100794CA2 /* BaseDataStore.swift in Sources */,
7D92423D224D7B9E009F84B5 /* FxAClient+.swift in Sources */,
Expand Down
49 changes: 15 additions & 34 deletions Shared/Store/BaseDataStore.swift
Expand Up @@ -9,20 +9,6 @@ import RxRelay
import RxOptional
import SwiftKeychainWrapper

enum SyncError: Error {
case CryptoInvalidKey
case CryptoMissingKey
case Crypto
case Locked
case Offline
case Network
case NeedAuth
case Conflict
case AccountDeleted
case AccountReset
case DeviceRevoked
}

enum SyncState: Equatable {
case Syncing, Synced, TimedOut

Expand All @@ -41,7 +27,7 @@ enum SyncState: Equatable {
}

enum LoginStoreState: Equatable {
case Unprepared, Locked, Unlocked, Errored(cause: LoginStoreError)
case Unprepared, Locked, Unlocked, Errored(cause: LoginsStoreError)

public static func ==(lhs: LoginStoreState, rhs: LoginStoreState) -> Bool {
switch (lhs, rhs) {
Expand All @@ -55,19 +41,6 @@ enum LoginStoreState: Equatable {
}
}

public enum LoginStoreError: Error {
// applies to just about every function call
case Unknown(cause: Error?)
case NotInitialized
case AlreadyInitialized
case VersionMismatch
case CryptoInvalidKey
case CryptoMissingKey
case Crypto
case InvalidItem
case Locked
}

class BaseDataStore {
private let queue = DispatchQueue(label: "Logins queue", attributes: [])

Expand Down Expand Up @@ -216,7 +189,7 @@ extension BaseDataStore {
private func touch(id: String) {
do {
try self.loginsStorage?.touch(id: id)
} catch let error as LoginStoreError {
} catch let error as LoginsStoreError {
self.pushError(error)
} catch let error {
NSLog("DATASTORE:: Unexpected LoginsStorage error -- \(error)")
Expand Down Expand Up @@ -250,7 +223,7 @@ extension BaseDataStore {

do {
try self.loginsStorage?.sync(unlockInfo: syncInfo)
} catch let error as LoginStoreError {
} catch let error as LoginsStoreError {
self.pushError(error)
} catch let error {
NSLog("DATASTORE:: Unknown error syncing: \(error)")
Expand All @@ -266,7 +239,7 @@ extension BaseDataStore {
do {
let loginRecords = try loginsStorage.list()
self.listSubject.accept(loginRecords)
} catch let error as LoginStoreError {
} catch let error as LoginsStoreError {
self.pushError(error)
} catch let error {
NSLog("DATASTORE:: Unknown error updating list: \(error)")
Expand Down Expand Up @@ -331,7 +304,7 @@ extension BaseDataStore {
do {
try loginsStorage.ensureUnlocked(withEncryptionKey: loginsKey)
self.storageStateSubject.onNext(.Unlocked)
} catch let error as LoginStoreError {
} catch let error as LoginsStoreError {
pushError(error)
} catch let error {
NSLog("Unknown error unlocking: \(error)")
Expand Down Expand Up @@ -365,9 +338,17 @@ extension BaseDataStore {
}
}

private func pushError(_ error: LoginStoreError) {
private func pushError(_ error: LoginsStoreError) {
self.storageStateSubject.onNext(.Errored(cause: error))
self.dispatcher.dispatch(action: SentryAction(title: "Datastore Error", error: error, line: nil))

switch error {
case .AuthInvalid, .InvalidKey:
self.dispatcher.dispatch(action: DataStoreAction.reset)
self.dispatcher.dispatch(action: AccountAction.clear)
default:
return
}
}

private func reset() {
Expand All @@ -379,7 +360,7 @@ extension BaseDataStore {
self.storageStateSubject.onNext(.Unprepared)
try loginsStorage.ensureUnlocked(withEncryptionKey: loginsKey)
try loginsStorage.wipeLocal()
} catch let error as LoginStoreError {
} catch let error as LoginsStoreError {
self.pushError(error)
} catch let error {
NSLog("Unknown error wiping database: \(error.localizedDescription)")
Expand Down

0 comments on commit a6cf858

Please sign in to comment.