bamurph / SweetPea

A little green podcast app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Realm errors should be caught and observed

bamurph opened this issue · comments

Create a "StoreErrorSubject" & "StoreErrorObserver" that will collect and handle errors from Realm operations.

 do {
            try write {
                let sub = Subscription()
                sub.title = title
                sub.summary = summary
                sub.xmlUrl = xmlUrl
                sub.htmlUrl = htmlUrl
                add(sub)
            }
        } catch {
            print(StoreError.addSubscriptionFailed(error).localizedDescription) // Errors should be sent from here
        }

https://realm.io/docs/swift/latest/#writes

Since write transactions incur non-negligible overhead, you should architect your code to minimize the number of write transactions.

Because write transactions could potentially fail like any other disk IO operations, both Realm.write() & Realm.commitWrite() are marked as throws so you can handle and recover from failures like running out of disk space. There are no other recoverable errors. For brevity, our code samples don’t handle these errors but you certainly should in your production applications.