-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove fatalError
in case of persistent store backup failure and add more logging to store migration
#2481
Remove fatalError
in case of persistent store backup failure and add more logging to store migration
#2481
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,34 +48,22 @@ public class CoreDataManager: StorageManagerType { | |
|
||
/// Backup the old Store | ||
/// | ||
var persistentStoreBackupError: Error? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not related to this line. Regarding
🙈 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ugh yea I don't feel super good about having |
||
do { | ||
let sourceURL = self.storeURL | ||
let backupURL = sourceURL.appendingPathExtension("~") | ||
try FileManager.default.copyItem(at: sourceURL, to: backupURL) | ||
} catch { | ||
let message = "☠️ [CoreDataManager] Cannot backup Store: \(error)" | ||
self.crashLogger.logMessageAndWait(message, | ||
properties: ["persistentStoreLoadingError": persistentStoreLoadingError, | ||
"backupError": error, | ||
"appState": UIApplication.shared.applicationState.rawValue, | ||
"migrationMessages": migrationDebugMessages], | ||
level: .fatal) | ||
fatalError(message) | ||
persistentStoreBackupError = error | ||
} | ||
|
||
/// Remove the old Store | ||
/// | ||
var persistentStoreRemovalError: Error? | ||
do { | ||
try FileManager.default.removeItem(at: self.storeURL) | ||
shiki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} catch { | ||
let message = "☠️ [CoreDataManager] Cannot remove Store: \(error)" | ||
self.crashLogger.logMessageAndWait(message, | ||
properties: ["persistentStoreLoadingError": persistentStoreLoadingError, | ||
"removeStoreError": error, | ||
"appState": UIApplication.shared.applicationState.rawValue, | ||
"migrationMessages": migrationDebugMessages], | ||
level: .fatal) | ||
fatalError(message) | ||
persistentStoreRemovalError = error | ||
} | ||
|
||
/// Retry! | ||
|
@@ -85,20 +73,27 @@ public class CoreDataManager: StorageManagerType { | |
return | ||
} | ||
|
||
let message = "☠️ [CoreDataManager] Recovery Failed! \(error) [\(error.userInfo)]" | ||
let message = "☠️ [CoreDataManager] Recovery Failed!" | ||
|
||
let logProperties: [String: Any?] = ["persistentStoreLoadingError": persistentStoreLoadingError, | ||
"persistentStoreBackupError": persistentStoreBackupError, | ||
"persistentStoreRemovalError": persistentStoreRemovalError, | ||
"retryError": error, | ||
"appState": UIApplication.shared.applicationState.rawValue, | ||
"migrationMessages": migrationDebugMessages] | ||
self?.crashLogger.logMessageAndWait(message, | ||
properties: ["persistentStoreLoadingError": persistentStoreLoadingError, | ||
"retryError": error, | ||
"appState": UIApplication.shared.applicationState.rawValue, | ||
"migrationMessages": migrationDebugMessages], | ||
properties: logProperties.compactMapValues { $0 }, | ||
level: .fatal) | ||
fatalError(message) | ||
} | ||
|
||
let logProperties: [String: Any?] = ["persistentStoreLoadingError": persistentStoreLoadingError, | ||
"persistentStoreBackupError": persistentStoreBackupError, | ||
"persistentStoreRemovalError": persistentStoreRemovalError, | ||
"appState": UIApplication.shared.applicationState.rawValue, | ||
"migrationMessages": migrationDebugMessages] | ||
self.crashLogger.logMessage("[CoreDataManager] Recovered from persistent store loading error", | ||
properties: ["persistentStoreLoadingError": persistentStoreLoadingError, | ||
"appState": UIApplication.shared.applicationState.rawValue, | ||
"migrationMessages": migrationDebugMessages], | ||
properties: logProperties.compactMapValues { $0 }, | ||
level: .info) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to this line.
I noticed that the errors we were getting are missing reasons for the failed migrations. For example:
It looks like we don't return any debugging messages for cases where we return
false
. Example:woocommerce-ios/Storage/Storage/CoreData/CoreDataIterativeMigrator.swift
Lines 31 to 33 in 4350b45
Do you think we should add messages for those?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking more closely, it looks like this will be handled by the
do catch
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are many points of failure in this function
CoreDataIterativeMigrator. iterativeMigrate
, and I think the most critical one is probably where it migrates the store in this call tomigrateStore
. later in this file I updated to return the error for each point of failure (actual migration error, or backup error) and adding this error todebugMessages
below (L113)