-
Notifications
You must be signed in to change notification settings - Fork 35
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
Not using try! #26
Not using try! #26
Conversation
Use do catch or use try? in combo with guard or if let
Hey @tapwork thanks for bringing this issue up and also for getting a fix together! The I think the |
Just in case my previous comment was unclear, I just wanted to hear your opinion on |
hey @loudmouth |
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.
@loudmouth I didn't change the code. I think it might be okayish as it used to be. Can you have a look into my comments
persistable = try self.persistentStore.create(type: type) | ||
persistable.id = asset.id | ||
} catch let error { | ||
fatalError("Could not create the Asset persistent store\n \(error)") |
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.
I would leave fatalError
here (so even crash in live world). There is no guarantee that the program will work properly without the model. (which is expected to exist). The creation of the model should only fail in really rare cases. If it fails something else is really broken.
@loudmouth what do you think?
persistable.id = entry.id | ||
persistable.createdAt = entry.sys.createdAt | ||
} catch let error { | ||
fatalError("Could not create the Entry persistent store\n \(error)") |
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.
do { | ||
try persistentStore.save() | ||
} catch let error { | ||
assertionFailure("Could not save the persistent store\n \(error)") |
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.
The program can live without a save
@@ -216,16 +227,19 @@ public class SynchronizationManager: PersistenceIntegration { | |||
|
|||
// Returns regular (non-relationship) field to property mappings. | |||
internal func propertyMapping(for entryType: EntryPersistable.Type, and fields: [FieldName: Any]) -> [FieldName: String] { | |||
// Filter out user-defined properties that represent relationships. | |||
guard let persistentRelationshipPropertyNames = try? persistentStore.relationships(for: entryType) else { | |||
assertionFailure("Could not filter out user-defined properties that represent relationships.") |
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.
I am not 100% sure if this is really necessary to filter out the items in order to have a stable running app.
@loudmouth what do you think?
let spacePersistable: SyncSpacePersistable = try self.persistentStore.create(type: self.persistenceModel.spaceType) | ||
return spacePersistable | ||
} catch let error { | ||
fatalError("Could not create the Sync Space persistent store\n \(error)") |
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.
I think the space is needed for the whole model, right @loudmouth ?
I think your approach is correct 👍 Just wanted to think about it. I'm going to merge now. Thanks again for the contribution! I'll add you to the changelog. |
@tapwork I will probably not be publishing a new version for the next few days, so you will want to point to |
thanks @loudmouth |
Use a proper
do catch
or use try? in combo withguard
orif let
and display the error to get more context in failure case.