Sync icon indicating copy to clipboard operation
Sync copied to clipboard

DataStack initializer crashes our app

Open vandadnp opened this issue 3 years ago • 7 comments

Describe the bug We got a crash report in Crashlytics today stating the following:

Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=640 "You can’t save the file “StoredModels.sqlite” because the volume “Data” is out of space." UserInfo={NSLocalizedFailureReason=Excluding SQLite file from backup caused an error, NSFilePath=/var/mobile/Containers/Data/Application/B50CAAAE-B135-4EB1-8725-854C1ABA24E1/Documents/StoredModels.sqlite, NSUnderlyingError=0x280235260 {Error Domain=NSPOSIXErrorDomain Code=28 "No space left on device"}, NSURL=file:///var/mobile/Containers/Data/Application/B50CAAAE-B135-4EB1-8725-854C1ABA24E1/Documents/StoredModels.sqlite}: file Sync/DataStack.swift, line 66

This is occurring on a telephone that doesn't have enough space to create a new DataStack and we have no initializers for DataStack that throws an error since there are a lot of explicitly unwrapped code like this:

extension NSManagedObjectModel {
    convenience init(bundle: Bundle, name: String) {
        if let momdModelURL = bundle.url(forResource: name, withExtension: "momd") {
            self.init(contentsOf: momdModelURL)!
        } else if let momModelURL = bundle.url(forResource: name, withExtension: "mom") {
            self.init(contentsOf: momModelURL)!
        } else {
            self.init()
        }
    }
}

To Reproduce Steps to reproduce the behavior:

  1. Get a phone that is almost running out of space
  2. Create a new datastack on it

Expected behavior The app shouldn't crash

iOS Version (please complete the following information): 14.2.0

Framework Version (please complete the following information):

  • Sync 6.0.0

vandadnp avatar Dec 14 '20 07:12 vandadnp

Hello @vandadnp,

You're right, the app shouldn't crash, it should fail gracefully sending an error saying "Free up some space to continue."

3lvis avatar Dec 15 '20 21:12 3lvis

We might need to change this to be a throwable init which will make it a breaking change

3lvis avatar Dec 15 '20 21:12 3lvis

@3lvis thanks for your reply and thank you for Sync 😊 Would it be possible to introduce a new static initializer? that way old clients continue to work as they did before and new clients that need the error handling can just call the static function to initialize a new datastack

vandadnp avatar Dec 16 '20 05:12 vandadnp

@3lvis would you like me to have a look at this and send a PR?

vandadnp avatar Jan 11 '21 09:01 vandadnp

@vandadnp I'm sorry for the lack of follow up, been drowning in other projects, please, if you're ok with it, happy to receive contributions

3lvis avatar Jan 30 '21 06:01 3lvis

Hi @3lvis

I've looked at this and it seems like I have to introduce, as you said, some breaking changes. Should I sent the PR anyways?

vandadnp avatar Feb 08 '21 09:02 vandadnp

@3lvis I sent the PR for your review

vandadnp avatar Feb 08 '21 12:02 vandadnp