Realm-cocoa: Realm Crash: when updated DB version (Not DB scheme) for swift 3

Created on 12 Dec 2016  路  11Comments  路  Source: realm/realm-cocoa

We LOVE to help with any issues or bugs you have!

Questions: If you have questions about how to use Realm, ask on
StackOverflow.
We monitor the realm tag.

Feature Request: Just fill in the first two sections below.

Bugs: To help you as fast as possible with an issue please describe your issue
and the steps you have taken to reproduce it in as many details as possible.

Thanks for helping us help you! :-)

Please remove this line and all above before submitting.

Goals

What do you want to achieve?

Expected Results

Fetch older data saved in database

Actual Results

Whenever try to access Realm DB , app crashed
e.g. the stack trace of a crash

Steps to Reproduce

What are steps we can follow to reproduce this issue?

Code Sample

Here is the crash log

0. Crashed: com.apple.main-thread

0 libswiftCore.dylib 0x101aa8a08 _TFs16_assertionFailedFTVs12StaticStringSSS_Su5flagsVs6UInt32_Os5Never + 164
1 libswiftCore.dylib 0x101ac87b8 swift_unexpectedError_merged + 476
2 libswiftCore.dylib 0x101ac85c0 swift_unexpectedError + 26
3 Justproperty 0x100235970 specialized specialized _insertionSort, by : inout (A.Iterator.Element, A.Iterator.Element) -> Bool) -> () (NotificationAlertsModel.swift)
4 Justproperty 0x100333174 specialized AppDelegate.removeReadNotifications() -> () (NotificationAlertsModel.swift)
5 Justproperty 0x100333928 specialized AppDelegate.application(UIApplication, didFinishLaunchingWithOptions : [UIApplicationLaunchOptionsKey : Any]?) -> Bool (AppDelegate.swift:67)
6 Justproperty 0x10032ea14 @objc AppDelegate.application(UIApplication, didFinishLaunchingWithOptions : [UIApplicationLaunchOptionsKey : Any]?) -> Bool (AppDelegate.swift)
7 UIKit 0x18a7db100 -[UIApplication _handleDelegateCallbacksWi
thOptions:isSuspended:restoreState:] + 400
8 UIKit 0x18a9eb858 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3524
9 UIKit 0x18a9f15c8 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1656
10 UIKit 0x18aa05e60 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke.3137 + 48
11 UIKit 0x18a9ee5ac -[UIApplication workspaceDidEndTransaction:] + 168
12 FrontBoardServices 0x1864b58bc __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36
13 FrontBoardServices 0x1864b5728 -[FBSSerialQueue _performNext] + 176
14 FrontBoardServices 0x1864b5ad0 -[FBSSerialQueue _performNextFromRunLoopSource] + 56
15 CoreFoundation 0x1848bc278 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
16 CoreFoundation 0x1848bbbc0 __CFRunLoopDoSources0 + 524
17 CoreFoundation 0x1848b97c0 __CFRunLoopRun + 804
18 CoreFoundation 0x1847e8048 CFRunLoopRunSpecific + 444
19 UIKit 0x18a7d42b0 -[UIApplication _run] + 608
20 UIKit 0x18a7cf034 UIApplicationMain + 208
21 Justproperty 0x1000af2ac main (AppDelegate.swift:22)
22 libdispatch.dylib 0x1837cc5b8 (Missing)

this is the exception from crashlytics

CRASH_INFO_ENTRY_0
fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=2 "Unable to open a realm at path '/var/mobile/Containers/Data/Application/DF6298EF-B141-417C-B13E-CA803D67F89F/Documents/default.realm': Unsupported Realm file format version." UserInfo={Error Code=2, NSFilePath=/var/mobile/Containers/Data/Application/DF6298EF-B141-417C-B13E-CA803D67F89F/Documents/default.realm, Underlying=Unsupported Realm file format version, NSLocalizedDescription=Unable to open a realm at path '/var/mobile/Containers/Data/Application/DF6298EF-B141-417C-B13E-CA803D67F89F/Documents/default.realm': Unsupported Realm file format version.}: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-800.0.58.6/src/swift/stdlib/public/core/ErrorType.swift, line 178

Version of Realm and Tooling

In the CONTRIBUTING guidelines, you will find a script,
which will help determining these versions.

Realm version: ? 2.0.1

Xcode version: ? Xcode 8.1

iOS/OSX version: ? iOS 10

Dependency manager + version: ? Cathage

T-Help

All 11 comments

@Sunitadaffodil The error message shows Unsupported Realm file format version. It means that the app tried to open a file created with a newer version of Realm. (For example, Realm 1.x can not open a file created by Realm 2.x). Can you make sure version of Realm you are using, and tell us more details? How do you create Realm instance?

Hi ,

For Release 2.5 (iOS 9) we were using Realm 1.1.0, but for Release 2.6 (iOS 10) we are using Realm 2.0.1. Now when users are updating app from 2.5->2.6, it crashes.

Also I am using Carthage. I am not creating DB specifically, its get created once try to write something in DB.

Please let me know, what's wrong I am doing.

Please let me know, what's wrong I am doing.

Hard to say without being able to reproduce this ourselves... @Sunitadaffodil can you share a project with us that triggers this issue? That's the best way you can help prioritize this and get it fixed.

Hi @Sunitadaffodil!

Are you still having this problem? If so, can you please re-open this issue and provide us with some code that would let us reproduce this issue?

Realm is very careful about upgrading its internal file format, even between older versions such as Realm 1.0 and 2.0, so this sort of issue shouldn't be happening.

Thanks! Happy holidays!

Looks like another developer had given up with Realm.

We getting error "Unsupported Realm file format version" sporadically on the same libraries.
Googled for this error and found nothing valuable.

Definitely not ready for production.

Hi... Sorry for late reply, In my case I was having this same issue and to resolve the issue I am deleting database file on app launch..this was just a quick fix which was possible in my case.. but I know may be in other cases where that older data is important..we can't simply delete older database file. But I have a strong feeling that this happened because of mismatch in realm versions..that's older realm version is trying to read database created by newer version. So for older version it would be "unsupported file"..

We started using Realm with 2.x libraries and got too many sporadic version incompatibility errors just in 1 week.
I'm sure this is a bug in Realm which makes it unstable.

I've decided to get rid of it and fall back to MagicalRecord. Fortunately, we using layered architecture and it should not be painful.

@AlexeyPoldeo I'm sorry you've found Realm to be unstable for you. If you file detailed reproducible bug reports, we're happy to fix them. So far, we have yet to get such reports.

With all my respect, probably you didn't get such reports because it happens sporadically and the developers just give up and switching to another solution.

In my case it happens on some of app's start and (after the crash) goes away and then works fine.

@jpsim Do you have any solution? I have same issue. My both app verions have same realm version 3.0.2

Well this happened to me when I was working on Swift 4 migration. So my newer branch had a later version of Realm installed. Switching to master and running the app would cause it to crash with the older version.

But if I removed the application from my phone after switching to master, and then building it works fine. Kind of a weird edge case for me since our users will never "go back" to an older version of Realm.

Was this page helpful?
0 / 5 - 0 ratings